【问题标题】:Accessing lists within multidimentional tuple访问多维元组中的列表
【发布时间】:2021-05-15 01:22:42
【问题描述】:

我是 Python 新手..

我可以通过将两个字典与dictdiffer 进行比较来生成以下输出,它位于oo 变量中:

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

我想访问 此元组中的列表,输出如下:

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

到目前为止我所做的只是looping by index value

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

但是输出是随机字母,并不是每个列表(以日期开头)都在那里!:

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

如何排列列表并从这个多元组变量中检索它们?

【问题讨论】:

    标签: python python-3.x list tuples


    【解决方案1】:

    数据结构似乎是元组和列表的元组。

    以下似乎可以达到预期的效果。

    
    oo = ('remove', '', [('we are here to help you improve your skills', [['2021-04-09', 'email@example.com', 'we are here to help you improve your skills', 'Delivered']]), ('(1st meeting) here is our recorded presentation skills webinar', [['2021-04-12', 'email@example.com', '(1st meeting) here is our recorded presentation skills webinar', 'Delivered']]), ('YOU ARE INVITED TO THIS PROGRAMMING EVENT', [['2021-04-13', 'email@example.com', 'YOU ARE INVITED TO THIS PROGRAMMING EVENT', 'Delivered'], ['2021-04-16', 'email@example.com', 'YOU ARE INVITED TO THIS PROGRAMMING EVENT', 'Delivered']])])
    ('remove', '', [('we are here to help you improve your skills', [['2021-04-09', 'email@example.com', 'we are here to help you improve your skills', 'Delivered']]), ('(1st meeting) here is our recorded presentation skills webinar', [['2021-04-12', 'email@example.com', '(1st meeting) here is our recorded presentation skills webinar', 'Delivered']]), ('YOU ARE INVITED TO THIS PROGRAMMING EVENT', [['2021-04-13', 'email@example.com', 'YOU ARE INVITED TO THIS PROGRAMMING EVENT', 'Delivered'], ['2021-04-16', 'email@example.com', 'YOU ARE INVITED TO THIS PROGRAMMING EVENT', 'Delivered']])])
    ('remove', '', [('we are here to help you improve your skills', [['2021-04-09', 'email@example.com', 'we are here to help you improve your skills', 'Delivered']]), ('(1st meeting) here is our recorded presentation skills webinar', [['2021-04-12', 'email@example.com', '(1st meeting) here is our recorded presentation skills webinar', 'Delivered']]), ('YOU ARE INVITED TO THIS PROGRAMMING EVENT', [['2021-04-13', 'email@example.com', 'YOU ARE INVITED TO THIS PROGRAMMING EVENT', 'Delivered'], ['2021-04-16', 'email@example.com', 'YOU ARE INVITED TO THIS PROGRAMMING EVENT', 'Delivered']])])
    
    
    for x in oo[2]:
        for y in x[1]: 
            print(y)
    

    返回

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

    【讨论】:

      猜你喜欢
      • 2021-12-01
      • 1970-01-01
      • 2021-12-04
      • 1970-01-01
      • 2015-07-05
      • 2020-01-15
      • 1970-01-01
      • 2023-03-11
      • 1970-01-01
      相关资源
      最近更新 更多