By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,852 Members | 2,152 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,852 IT Pros & Developers. It's quick & easy.

How does this code works?

P: 2
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(line.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(line.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?
May 8 '17 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.