-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnew_file.py
35 lines (35 loc) · 896 Bytes
/
new_file.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
33
34
35
file = open ('demon.txt','r')
data = file.readlines()
print(data)
def read_file(file_path):
file = open(file_path, 'r')
data =file.readlines ()
map_={}
for elem in data:
sub, name = elem.split()
lst = sub.split() ['Maths', 'Shivank']
if sub in map_:
map_[sub].add(name)
else:
map_[sub] = {name}
file.close()
return map_
map_ = read_file('../demo.txt')
print(map_)
def read_file_and_return_map(file_path):
file = open(file_path, 'r')
data = file.read()
map_ = {}
lst=[]
count = 0
for i in data:
count = count + 1
lst= i.split()
if i in map_:
map_[i].add(count)
else:
map_[i] = {count}
file.close()
return map_
map_ = read_file_and_return_map('../demon.txt')
print(map_)