【问题标题】:Finding Element of List that is already inside a List [duplicate]查找已经在列表中的列表元素[重复]
【发布时间】:2021-07-31 01:05:18
【问题描述】:

我正在尝试查找 List_00 或 List_01 的元素,它们都在名为 combine_list 的单个列表中。我怎样才能找到它?

#consists intergers
list_00 = [1, 2, 33, 100, 69]

#consists strings
list_01 = ['Jack', "Sam", "Trump"]

#both list combined in a single list to perform other experimental operations
combined_list = [list_00 , list_01]

#desired output: any single item of any of the above list 

【问题讨论】:

  • “所需的输出:任何单个项目...”combined_list[0][0]。如果这不是您期望的输出,请提供您期望的输出。
  • 这能回答你的问题吗? common elements in two lists python
  • 我想要 1 或 Jack 或两个列表中的任何一个中的任何其他元素作为输出
  • @trincot 你的答案是正确的,非常感谢

标签: python-3.x


【解决方案1】:

和你做的一样,只是使用索引号访问combined_list的元素,就像二维数组一样:

>>> list_00 = [1, 2, 33, 100, 69]
>>> list_01 = ['Jack', "Sam", "Trump"]
>>> combined_list = [list_00 , list_01]
>>> print(combined_list)
[[1, 2, 33, 100, 69], ['Jack', 'Sam', 'Trump']]
>>> print(combined_list[0][1])
2
>>> print(combined_list[1][2])
Trump

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-08-08
    • 2021-01-01
    • 2014-01-08
    • 2014-04-21
    • 2015-05-23
    • 2010-10-10
    • 2018-11-11
    • 2016-01-11
    相关资源
    最近更新 更多