troubleshooting Question

Sort a list of lists

Avatar of dfernan
dfernanFlag for United States of America asked on
PythonProgramming
3 Comments1 Solution1885 ViewsLast Modified:
if i have a list of lists like this one: (the one i have is obviously much larger but this is the idea):
new = [['dog',2],['cat',5],['bye',1]]
...
how can i sort it according to the numbers on the second column, i.e., new[0][1]=2....?
i.e., new.sort should become: new.sort(sthg) = [['bye',1],['dog',2],['cat',5]]

How can i access all the numbers in the second column together like it was a vector?
i.e., new[sthg][sthg] = [2,5,1]

How would you sort it alphabetically up/down?
i.e., alphabetically up: new.sort should become: new.sort(sthg) = [['bye',1],['cat',5],['dog',2]]
i.e., alphabetically down: new.sort should become: new.sort(sthg) = [['dog',2],['cat',5],['bye',1]]


Another basic question:
if i have a list L, L[:] means what?????

I am a newbie in python...

Thanks for the help,

Daniel
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros