regex - How to convert list to float in Python -


i'm trying write program lines of form

new revision: 39772 

extract numbers, , find average. here code:

import re import statistics  file_name = raw_input("enter file: ") file = open(file_name) revision_nums = []  line in file:     line = line.rstrip()     x = re.findall("new revision: (\d+)", line)     if len(x) > 0:         revision_nums.append(x)  print statistics.mean(revision_nums) 

however, realized elements in revision_nums stored lists, , i'm getting error when try run it:

typeerror: can't convert type 'list' numerator/denominator 

i tried:

for in revision_nums:     j in i:         j = float(j) 

and returns same error. doing wrong , how can fix this?

x list, if re.findall found 1 match. try revision_nums.append(x[0])


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -