help, keep getting valueerror: invalid literal int() base 10: '' when try extract integer string!
from string import capwords import sys,os import re def parseint(list): newlist = [i in list if isinstance(i, int)] return newlist def getint(string): number = [int(x) x in string.split("-")] return number file=open('./class 1/usr_score.data','r') text=file.read() def get_num(x): return int(''.join(ele ele in x if ele.isdigit())) split = text.split(",") split.sort(key = lambda k : k.lower()) in split: print(i) print ('---------------------------------------') list1=[] in split: list1.append(str(i)) num_list1=[] in list1: ints = re.findall(r'\b\d+\b', i) #ints = getint(i)[0] in ints: int1=i num_list1.append(i) #num_list1 = parseint(list1) num_list=num_list1 in num_list: print(i)
the file usr_score.data contains:
user-1,aaa-1,usr-3,aaa-4,
what code is contains scores game , want program sort them alphabetical order. can please fix problem?
note: of code in program has not been used.
your input data has ',' @ end, causes split() generate empty string in addition scores:
['user-1', 'aaa-1', 'usr-3', 'aaa-4', '']
int('')
doesn't work; should either remove empty string, or deal it.
Comments
Post a Comment