Click here to Skip to main content
15,889,883 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
There is a lot function involved but im gonna keep it simple :


Here is my code :

[['Musique', 'Initiation au tango argentin suivi de la milonga', 182, 231], ['Musique', 'The Singing Pianos', 216, 216], ['Musique', 'Rythmes et détente : Duo Pichenotte', 216, 216]]


I want to return only the index [1] of every sublist as strings. It's in french but the index [1] is the title of every sublists. Every sublists are an event and i need to return only the name. There is actually a lot more events in my code but i want a simple code and ill do my best with it.

So if we're looking at the code sample i gave you i would have to return :

Initiation au tango argentin suivi de la milonga
The Singing Pianos
Rythmes et détente : Duo Pichenotte

If there was a way to return them of different lines like my return, thatd be great too.

What I have tried:

Im having a hard time using index in a list of sublists. It's important to return only the title as str of every lists. i tried using a while like

while i < len(events):

print(events[i][:1])  # That would search every index and return every index i need
but it didnt work. there is more code involved but you get the picture and i dont want to add 8 functions to this scenario.
Posted
Updated 21-Oct-18 22:31pm
v2

1 solution

What's wrong with
Python
events = [['Musique', 'Initiation au tango argentin suivi de la milonga', 182, 231], ['Musique', 'The Singing Pianos', 216, 216], ['Musique', 'Rythmes et détente : Duo Pichenotte', 216, 216]]

for ev in events:
  print(ev[1])
?
 
Share this answer
 
v3
Comments
Member 13870077 22-Oct-18 13:41pm    
Its only returning 1 element cuz its in a return of a function, why ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900