Hi , I am beginner at python and programming. I have been doing some exercises about counting average from txt file.
txt file data is like this.
1 : 4.25
2 : 3.97
3 : 1.45
4 : 2.33
python code is like this.
name = []
for line in open("fileData. txt").readlines ():
name.append(lin e.strip().split (':')[1])
name = map(float,name)
avg = sum(name)/len(name)
print avg
Can anyone help me explaining in a simple way in this code ,
1.what does map in this code works?
2. name.append(lin e.strip().split (':')[1])
for this line , what I understand is data from txt file is inserted to the array.What does split(':') and [1] do?
txt file data is like this.
1 : 4.25
2 : 3.97
3 : 1.45
4 : 2.33
python code is like this.
name = []
for line in open("fileData. txt").readlines ():
name.append(lin e.strip().split (':')[1])
name = map(float,name)
avg = sum(name)/len(name)
print avg
Can anyone help me explaining in a simple way in this code ,
1.what does map in this code works?
2. name.append(lin e.strip().split (':')[1])
for this line , what I understand is data from txt file is inserted to the array.What does split(':') and [1] do?