【问题标题】:Search for elements in a List of Lists in python在 python 中的列表列表中搜索元素
【发布时间】:2023-01-04 21:46:25
【问题描述】:

我正在用 Python 编写代码。该代码应读取超过 200 万行的文本文档。每行包含 3 个数字。我已经写了一个代码来将 3 个数字存储在 3 个不同的变量中。这些变量存储在一个名为“点”的列表中。之后,我将列表“Point”附加到另一个名为“Coordinates”的列表。

现在我想搜索特定的点。搜索算法应该只扫描前 2 个索引号,因为最后一个数字仅用于高度测量。

有没有人有想法,我怎么能意识到这一点?

非常感谢你!

我无法尝试任何事情,因为我不知道这怎么可能:(

【问题讨论】:

  • 请显示您正在处理的代码

标签: python list search indexing


【解决方案1】:

我通常不会在没有尝试的情况下回答问题。但如果你真的无法开始,这是一个基本的方法:

looking_for = (100,100)

for point in coordinates:
   if point[0] == looking_for[0] and point[1] == looking_for[1]:
       print(f"the point is: {point}")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-11
    • 2015-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多