Nov-03-2019, 01:57 PM
I've been struggling with this for a couple of days now
I'm trying to pull a list from a text file in the format below
convert the numbers to int and sort by the numbers and not the str.
I can pull the numbers only and get it to work but when trying to put them back in
I get that it has to be a string. Any help would be great.
The goal is to pull the lines of text sort by the number then write them back to the text file.
Thanks
I'm trying to pull a list from a text file in the format below
convert the numbers to int and sort by the numbers and not the str.
I can pull the numbers only and get it to work but when trying to put them back in
I get that it has to be a string. Any help would be great.
The goal is to pull the lines of text sort by the number then write them back to the text file.
Thanks
# text file list ['13,pops','15,bubble','150,nano','33,party','pokey'] def getIt(): lst = [] with open("scores.txt", "r")as file: data = file.read().splitlines() newlst = data.copy() print(sorted(newlst, key=lambda x: int(x[0].split(",")[0]))) ## conv = [] ## ## for info in data: ## conv.append(int(info.split(",")[0])) ## ## print(sorted(conv, reverse = True)) ## ## print(data) #newdata = data.copy() getIt()
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags
Download my project scripts
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags
Download my project scripts