简体   繁体   English

使用 Python 搜索项目列表并返回列表的所有元素

[英]Search a list of Item Lists and return all elements of list with Python

I have a large list of lists that looks like this...我有很多看起来像这样的列表......

[[16W1509462 , FR-CHJAV-VSDB4234HL , 30.5, 42.0, 0.75, JAVA ], [[16W1509462, FR-CHJAV-VSDB4234HL, 30.5, 42.0, 0.75, JAVA],

[16W1509463 , FR-CHJAV-BT-VSDB4234HL , 30.5, 42.0, 0.75, JAVA ], [16W1509463, FR-CHJAV-BT-VSDB4234HL, 30.5, 42.0, 0.75, JAVA],

[16W1509463 , FR-CHJAV-BT-VSDB4234HL , 30.5, 42.0, 0.75, JAVA ], [16W1509463, FR-CHJAV-BT-VSDB4234HL, 30.5, 42.0, 0.75, JAVA],

[16W1509473 , FR-CHJAV-BT-VSDB4234HR , 30.5, 42.0, 0.75, JAVA ], [16W1509473, FR-CHJAV-BT-VSDB4234HR, 30.5, 42.0, 0.75, JAVA],

[16W1509473 , FR-CHJAV-BT-VSDB4234HR , 30.5, 42.0, 0.75, JAVA ], [16W1509473, FR-CHJAV-BT-VSDB4234HR, 30.5, 42.0, 0.75, JAVA],

[16W1509481 , FR-CHJAV-VSDB4834HD , 30.5, 48.0, 0.75, JAVA ], [16W1509481, FR-CHJAV-VSDB4834HD, 30.5, 48.0, 0.75, JAVA],

[16W1509481 , FR-CHJAV-VSDB4834HD , 30.5, 48.0, 0.75, JAVA ], [16W1509481, FR-CHJAV-VSDB4834HD, 30.5, 48.0, 0.75, JAVA],

[16W1509503 , FR-CHJAV-BT-VSDB6034HD , 30.5, 60.0, 0.75, JAVA ], [16W1509503, FR-CHJAV-BT-VSDB6034HD, 30.5, 60.0, 0.75, JAVA],

[16W1509503 , FR-CHJAV-BT-VSDB6034HD , 30.5, 60.0, 0.75, JAVA ]] [16W1509503, FR-CHJAV-BT-VSDB6034HD, 30.5, 60.0, 0.75, JAVA]]

I'm developing a program for my company so when an operator scans an item(the first element in the list is the item number), it will show them the description, length, width, thickness, and paint color.我正在为我的公司开发一个程序,所以当操作员扫描一个项目时(列表中的第一个元素是项目编号),它将向他们显示描述、长度、宽度、厚度和油漆颜色。

I would like to store the item number they scan in a variable then search for that item in the list of lists then show them the specs of the item such as length, width, thickness so on.我想将他们扫描的项目编号存储在一个变量中,然后在列表列表中搜索该项目,然后向他们显示项目的规格,例如长度、宽度、厚度等。

I've checked many other forums and to no avail I have not found anything that seems to do what I need so I'm not sure if this is even possible我检查了许多其他论坛但无济于事我没有找到任何似乎可以满足我需要的东西所以我不确定这是否可能

Essentially I would like the output to look like this本质上我希望输出看起来像这样


Item scanned: 16W1509462扫描项目:16W1509462

16W1509462 , FR-CHJAV-VSDB4234HL , 30.5, 42.0, 0.75, JAVA 16W1509462 , FR-CHJAV-VSDB4234HL , 30.5, 42.0, 0.75, JAVA

I assuming that each value stored in the nested list is a string except for the numbers.我假设存储在嵌套列表中的每个值都是一个字符串,除了数字。 Also, I am assuming that there are no duplicate item numbers like in your sample list.另外,我假设您的示例列表中没有重复的项目编号。 Then this should work, if I understood your question properly.如果我正确理解了您的问题,那么这应该可以工作。

item_to_scan = '16W1509462'
for sample in sample_list:
    if sample[0] == item_to_scan:
        print(sample) # or you can do whatever you want to do with the sample

Input:输入:

sample_list = [
    ['16W1509462', 'FR-CHJAV-VSDB4234HL', 30.5, 42.0, 0.75, 'JAVA'],
    ['16W1509463', 'FR-CHJAV-BT-VSDB4234HL', 30.5, 42.0, 0.75, 'JAVA'],
    ['16W1509473', 'FR-CHJAV-BT-VSDB4234HR', 30.5, 42.0, 0.75, 'JAVA'],
]

Output:输出:

['16W1509462', 'FR-CHJAV-VSDB4234HL', 30.5, 42.0, 0.75, 'JAVA']

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM