On 25.10.2016 10:09, niraj pandey wrote:
Try this.
my_string = '0,1,2,3'
my_lst=my_string.split(",")
leng = len(my_lst)
b=sum(my_lst)
avg=float(b/leng)
print avg
better try things yourself before suggesting them to others:
>>> my_string = '0,1,2,3'
>>> my_lst=my_string.split(",")
>>> leng = len(my_lst)
>>> b=sum(my_lst)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'int' and 'str'
This is exactly why the OP had to come up with his comprehension solution.
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor