I am new to python and working on a small project
NE = [ ("Maine", 30840, 1.329), ("Vermont", 9217, .626), ("New Hampshire", 8953,1.321), ("Massachusetts", 7800, 6.646), ("Connecticut", 4842, 3.59), ("Rhode Island", 1044, 1.05)]
where[0] is a state,[1] is land area,[2] is population
I have written the below code to sort in descending order of population
def s_sort(state):
return state[2]
s_state = sorted(NE,key=s_sort,reverse=True)
print(s_state)
Output:
[('Vermont', 9217, 0.626), ('Rhode Island', 1044, 1.05), ('New Hampshire', 8953, 1.321), ('Maine', 30840, 1.329), ('Connecticut', 4842, 3.59), ('Massachusetts', 7800, 6.646)]
But how do I only return the name of the states from the above output in the same descending order within this function?
My desired output:
Vermont,Rhode Island,New Hampshire,Maine,Connecticut,Massachusetts