MTALY
MTALY

Reputation: 1782

Accessing lists within multidimentional tuple

I am new to Python ..

I am able to generate the following output by comparing two dictionaries with dictdiffer and it is in oo variable:

oo = ('remove', '', [('we are here to help you improve your skills', [['2021-04-09', '[email protected]', 'we are here to help you improve your skills', 'Delivered']]), ('(1st meeting) here is our recorded presentation skills webinar', [['2021-04-12', '[email protected]', '(1st meeting) here is our recorded presentation skills webinar', 'Delivered']]), ('YOU ARE INVITED TO THIS PROGRAMMING EVENT', [['2021-04-13', '[email protected]', 'YOU ARE INVITED TO THIS PROGRAMMING EVENT', 'Delivered'], ['2021-04-16', '[email protected]', 'YOU ARE INVITED TO THIS PROGRAMMING EVENT', 'Delivered']])])
('remove', '', [('we are here to help you improve your skills', [['2021-04-09', '[email protected]', 'we are here to help you improve your skills', 'Delivered']]), ('(1st meeting) here is our recorded presentation skills webinar', [['2021-04-12', '[email protected]', '(1st meeting) here is our recorded presentation skills webinar', 'Delivered']]), ('YOU ARE INVITED TO THIS PROGRAMMING EVENT', [['2021-04-13', '[email protected]', 'YOU ARE INVITED TO THIS PROGRAMMING EVENT', 'Delivered'], ['2021-04-16', '[email protected]', 'YOU ARE INVITED TO THIS PROGRAMMING EVENT', 'Delivered']])])
('remove', '', [('we are here to help you improve your skills', [['2021-04-09', '[email protected]', 'we are here to help you improve your skills', 'Delivered']]), ('(1st meeting) here is our recorded presentation skills webinar', [['2021-04-12', '[email protected]', '(1st meeting) here is our recorded presentation skills webinar', 'Delivered']]), ('YOU ARE INVITED TO THIS PROGRAMMING EVENT', [['2021-04-13', '[email protected]', 'YOU ARE INVITED TO THIS PROGRAMMING EVENT', 'Delivered'], ['2021-04-16', '[email protected]', 'YOU ARE INVITED TO THIS PROGRAMMING EVENT', 'Delivered']])])

I would like to access the lists within this tuple, with an output like:

['2021-04-09', '[email protected]', 'we are here to help you improve your skills', 'Delivered']
['2021-04-12', '[email protected]', '(1st meeting) here is our recorded presentation skills webinar', 'Delivered']
['2021-04-13', '[email protected]', 'YOU ARE INVITED TO THIS PROGRAMMING EVENT', 'Delivered']
 ......
 ......

What I did so far is simply looping by index value:

for tuple in enumerate(oo):
    for list in tuple[1]:
        for activity in list:
            print(activity[0])

However the output is with random letters and not every list (starting with date) is there!:

r
e
m
o
v
e
w
['2021-04-09', '[email protected]', 'we are here to help you improve your skills', 'Delivered']
(
['2021-04-12', '[email protected]', '(1st meeting) here is our recorded presentation skills webinar', 'Delivered']
Y
['2021-04-13', '[email protected]', 'YOU ARE INVITED TO THIS PROGRAMMING EVENT', 'Delivered']

How can I arrange lists and able to retrieve them from this multi tuple variable?

Upvotes: 1

Views: 42

Answers (1)

Joe Thor
Joe Thor

Reputation: 1260

The data structure seems to be tuples of tuples and lists.

The below seems to work to get the desired results.


oo = ('remove', '', [('we are here to help you improve your skills', [['2021-04-09', '[email protected]', 'we are here to help you improve your skills', 'Delivered']]), ('(1st meeting) here is our recorded presentation skills webinar', [['2021-04-12', '[email protected]', '(1st meeting) here is our recorded presentation skills webinar', 'Delivered']]), ('YOU ARE INVITED TO THIS PROGRAMMING EVENT', [['2021-04-13', '[email protected]', 'YOU ARE INVITED TO THIS PROGRAMMING EVENT', 'Delivered'], ['2021-04-16', '[email protected]', 'YOU ARE INVITED TO THIS PROGRAMMING EVENT', 'Delivered']])])
('remove', '', [('we are here to help you improve your skills', [['2021-04-09', '[email protected]', 'we are here to help you improve your skills', 'Delivered']]), ('(1st meeting) here is our recorded presentation skills webinar', [['2021-04-12', '[email protected]', '(1st meeting) here is our recorded presentation skills webinar', 'Delivered']]), ('YOU ARE INVITED TO THIS PROGRAMMING EVENT', [['2021-04-13', '[email protected]', 'YOU ARE INVITED TO THIS PROGRAMMING EVENT', 'Delivered'], ['2021-04-16', '[email protected]', 'YOU ARE INVITED TO THIS PROGRAMMING EVENT', 'Delivered']])])
('remove', '', [('we are here to help you improve your skills', [['2021-04-09', '[email protected]', 'we are here to help you improve your skills', 'Delivered']]), ('(1st meeting) here is our recorded presentation skills webinar', [['2021-04-12', '[email protected]', '(1st meeting) here is our recorded presentation skills webinar', 'Delivered']]), ('YOU ARE INVITED TO THIS PROGRAMMING EVENT', [['2021-04-13', '[email protected]', 'YOU ARE INVITED TO THIS PROGRAMMING EVENT', 'Delivered'], ['2021-04-16', '[email protected]', 'YOU ARE INVITED TO THIS PROGRAMMING EVENT', 'Delivered']])])


for x in oo[2]:
    for y in x[1]: 
        print(y)

returns

['2021-04-09', '[email protected]', 'we are here to help you improve your skills', 'Delivered']
['2021-04-12', '[email protected]', '(1st meeting) here is our recorded presentation skills webinar', 'Delivered']
['2021-04-13', '[email protected]', 'YOU ARE INVITED TO THIS PROGRAMMING EVENT', 'Delivered']
['2021-04-16', '[email protected]', 'YOU ARE INVITED TO THIS PROGRAMMING EVENT', 'Delivered']

Upvotes: 1

Related Questions