Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jun 29, 2011, 12:32 PM   #1
rien333
macrumors regular
 
Join Date: Jun 2010
Location: The Netherlands
Python code question

I've been working on a project in Python today, but I can't find a solution for a problem I encountered a few hours ago. It would be great if I can finish my project tomorrow and I thought maybe someone around here is able to help me, because I just can't figure out a way to do the following thing myself:
Here is the code:
Code:
a_list =[[1,2,3,"I"],[4,7,"Cl"],[8,"Br"],[9,10,"F"]]
What I want, if it is possible at all, is that this list or a similar list becomes sorted alphabetically like this:
Code:
a_list = [[8,"Br"],[4,7,"Cl"],[9,10,"F"],[1,2,3,"I"]]
Hope I'm clear enough (For some reason I don't think I am...).
Hope one of your guys is able to help me! Or point me at some sort of direction.
__________________
Macrumors newbie, happy to be here! (And sorry if any of my English is incorrect)
rien333 is offline   0 Reply With Quote
Old Jun 29, 2011, 12:53 PM   #2
ehoui
macrumors regular
 
Join Date: Jan 2011
Look up the "sorted" built-in function. Your lambda function is going to look at the last item in the list:

Code:
sorted(a_list, key = lambda x: x[-1] )
ehoui is offline   1 Reply With Quote
Old Jun 29, 2011, 01:01 PM   #3
rien333
Thread Starter
macrumors regular
 
Join Date: Jun 2010
Location: The Netherlands
Wow, thanks! I really appreciate your help!
__________________
Macrumors newbie, happy to be here! (And sorry if any of my English is incorrect)
rien333 is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Library for simple Face and QR Code/Bar Code/Etc detection DarthFoley iPhone/iPad Programming 0 Jan 26, 2014 01:11 PM
Python to X Code taptic Mac Programming 12 Mar 8, 2013 12:15 PM
Ripit question (code for registration) Primejimbo Apple TV and Home Theater 0 Jan 7, 2013 06:21 PM
My Macintosh 512K is a Sad Mac. Error code question minifridge1138 Apple Collectors 7 Nov 4, 2012 01:10 AM
Python 3.2.3 dboxall123 Mac Programming 4 Sep 27, 2012 11:53 AM

Forum Jump

All times are GMT -5. The time now is 02:05 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC