Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
So i have a list of list:


[['Musique', 'Shawn Phillips', '2018-08-24', '2018-08-24'], ['Musique', "L'avenue Royale fête l'été!", '2018-08-25', '2018-08-25'], ['Musique', 'Perséides musicales', '2018-08-03', '2018-08-03'], ['Musique', 'Gaétan Leclerc chante Félix et…', '2018-08-17', '2018-08-17'], ['Musique', 'The Ring of Fire : a Johnny Cash Experience', '2018-07-21', '2018-07-21'],


Im looking to extract only the months and days of every lists and i want to use them in another function. but im having a hard time extracting the months and days only.

I need to put them in this function :

def obtain_date(date):



the list of lists is actually another function too obtain_events and after i extracted my months/days, im gonna have to find the exact days with another function, but im mostly focused on finding how i can extract the months and days only while having only 1 argument in my obtain_date(date): function. Also, after( or before) i extract the months/days, i need to change them to int, as they are currently in a form of strings.

What I have tried:

Tried a few loops like:

for element in obtain_events:
           if '2018' in element:
                 element.remove(2018)


But it didnt work and i also tried a few other loops but im getting confused.
Posted
Updated 12-Oct-18 22:12pm
Comments
MadMyche 12-Oct-18 15:23pm    
I am not a python developer, but I will say you are most likely over-complicating this. If you look at the actual data you have it is delimited text. There should be more than enough parsers for that to work with
Member 13870077 13-Oct-18 14:56pm    
it wont return anything when i print, why ?

1 solution

Python
for element in obtain_events:
           if '2018' in element:
                 numbers = element.split('-')
                 ...

The variable numbers will be a list containing something like: [ '2018', '08', '24' ]. You can now do what you want with each field, if necessary converting them to integer values.
 
Share this answer
 
Comments
Member 13870077 13-Oct-18 14:40pm    
Oh my, totally forgot about split, ill let you know if it works, but it should
Member 13870077 13-Oct-18 14:56pm    
it wont return anything when i print, why ?
Richard MacCutchan 14-Oct-18 3:07am    
I have no idea what your code is doing so I cannot answer that.

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