Reputation: 71
This is a homework. I'm not looking for answers, just a nudge into the right direction.
Given a list:
['The Boy','1:34','Let go','4:21','Wherever to', '5:30']
I want to be able to sort the list by pairs:
[['The Boy','1:34']['Let go','4:21']['Wherever to', '5:30']]
Upvotes: 2
Views: 3101
Reputation: 304215
Difficult without knowing which parts of Python you have been taught so far, but here are some steps that may help
>>> ['The Boy','1:34','Let go','4:21','Wherever to', '5:30'][::2]
['The Boy', 'Let go', 'Wherever to']
>>> ['The Boy','1:34','Let go','4:21','Wherever to', '5:30'][1::2]
['1:34', '4:21', '5:30']
>>> zip(['The Boy', 'Let go', 'Wherever to'], ['1:34', '4:21', '5:30'])
[('The Boy', '1:34'), ('Let go', '4:21'), ('Wherever to', '5:30')]
You should use some variables instead of repeating the list over and over of course
Upvotes: 4
Reputation: 226366
Actual code left for homework ;-)
Upvotes: 2