Read the task instructions that are included in the comments in the code, and then get started!
You can either edit and code online in repl.it or alternatively, you can simply cut and paste the below into your own python file
Solve the challenge on repl.it""" ==============TASK Several applications will require you to carry out a Sort. 1. Using the existing code below, adapt it to get the program to sort by USER ID (001 first) 2. Print the results to the screen (as a list) (it doesn't need t be necessarily printed back to the file) """ import csv #1. This code snippet sorts the file by index 2 (last name) using lambda with open('fakefacebook_write.txt','r',newline="") as f: #open the file in read mode reader=csv.reader(f) sorted_list=list(reader)#turn the reader iterator into a list sorted_list.sort(key=lambda x:x[2]) #use index 02 as the column to sort by, in this case last name #print(sorted_list) #this will simply print the sorted list --> Below is a prettier (formatted) print print("\n".join(str(row) for row in sorted_list)) # prettier print
Filename:fakefacebook_write.txt
ID,firstname, lastname,username,password,email,no_of_likes 001,Ruth,Marvin,marvR,pass123,[email protected],400 002,Carter,Smith,smithC,open123,[email protected],200 003,Joe,Blogs, blogsJ,2bg123,[email protected],99 004,Ruth,Pigachee,pigR,pig123,[email protected],72
A sample flow chart (design) for this particular challenge could look like:
Test No. | Description | Test Data(input) | Expected Outcome | Actual Outcome | Further Action? |
---|---|---|---|---|---|
1 | |||||
2 | |||||
3 | |||||
4 | |||||
5 |