in Education by
HOW DO I SORT THIS BY BIRTHYEAR IN ASCENDING ORDER? I'm distance learning student and have no help. I have a .txt file with this form: I'm trying to get that .txt in a list and sort it by birth year. Brett Finch, 1839 Third, 1992 David Edwards, 290 Locust, 1985 Mia Palm, 33 Birch, 1980 I pieced this from multiple sources and it's only getting worse! Any help is greatly appreciated!!! lstneedssorted = [] f3 = open("file3.txt") print("\nMerged Doctors Data: ") Count = 0 for lx in f3: print(lx.rstrip()) lx = lx.strip().split(",") #strVal = lx lstneedssorted.sort([lx[0], lx[1], lx[2]]) print(lstneedssorted) JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
You need to append each row to the lstneedssorted list. You can use the csv module to automatically parse the CSV file, instead of using .strip().split(',') When sorting, you use the key option to specify how to get the sort key from each item. In this case, the date is line[2]. import csv lstneedssorted = [] with open("file3.txt") as f3: c = csv.reader(f3) for lx in c: lstneedssorted.append(lx) lstneedssorted.sort(key = lambda line: line[2]) print(lstneedssorted)

Related questions

0 votes
    I have list1 of a certain length and list2 of a certain length. Let's say: list1 = [32, 345, ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 16, 2022 in Education by JackTerrance
0 votes
    The data are kept in a list whose elements are dictionaries, where each dictionary contains the data for a ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    How can I return the list in alphabets? I have sequence translator, and a python code that reads both ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 9, 2022 in Education by JackTerrance
0 votes
    A bag contains 50 tickets numbered 1, 2, 3, .., 50 of which five are drawn at random and arranged in ascending order of magnitude (x1...
asked Nov 15, 2021 in Education by JackTerrance
0 votes
    I want each item to be sorted by a specific property value from a list of dictionaries I have. Take the ... When sorted by name Select the correct answer from above options...
asked Jan 20, 2022 in Education by JackTerrance
0 votes
    This is a sample (edited slightly, but you get the idea) of my XML file: Test 192.168.1.1 Test ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 19, 2022 in Education by JackTerrance
0 votes
    Which of the following sort a dataframe by the order of the elements in B? (a) x[rev(order(x$B)), ... Regression of R Programming Select the correct answer from above options...
asked Feb 10, 2022 in Education by JackTerrance
0 votes
    title basically. The question says create a function that takes in a string and returns true when the ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    title basically. The question says create a function that takes in a string and returns true when the ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    I have some data either in a list of lists or a list of tuples, like this: data = [[1,2,3], [4,5, ... store tuples or lists in my list? Select the correct answer from above options...
asked Feb 4, 2022 in Education by JackTerrance
0 votes
    The digits 1,2,3,4,5,6,7,8 and 9 are written in random order to form a nine digit number. The probability that this ... 2 9 2 D. 7 9 7 Select the correct answer from above options...
asked Nov 15, 2021 in Education by JackTerrance
0 votes
    Currently, I'm using Spring boot with DynamoDB and using DynamoDBMapper for all DB operation. Right now it' ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 20, 2022 in Education by JackTerrance
0 votes
    I've got a large array of primitive types (double). How do I sort the elements in descending ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 5, 2022 in Education by JackTerrance
0 votes
    What is the default SORT order for a SQL? (a) Ascending (b) Descending (c) As specified by ... and Answers, Database Interview Questions and Answers for Freshers and Experience...
asked Oct 11, 2021 in Education by JackTerrance
...