-
Notifications
You must be signed in to change notification settings - Fork 0
/
Company_listed.py
32 lines (26 loc) · 1.02 KB
/
Company_listed.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
folder_location = 'C:\\Users\\willi\\Documents\\Python\\Project_Files\\' # Can be changed to input value
file = 'nasdaqlisted.txt' # Can be changed to input value
sorted_file = 'nasdaq_listed.txt' # Can be changed to input value
with open(folder_location + file, mode='r') as in_file:
list_text = []
for line in in_file:
start = False
symbol = ''
company_name = ''
for s in line:
if s == '|':
break
else:
symbol = symbol + s
for c in line:
if c == '.' or c == '-' or (c == '|' and start):
break
if c == '|':
start = True
elif start:
company_name = company_name + c
list_text.append(symbol + ';' + company_name)
continue
with open(folder_location + sorted_file, mode='w') as out_file:
for element in list_text:
out_file.write(element + '\n')