简体   繁体   English

谁能告诉我这条线在我的 python 代码中做了什么:

[英]can anyone please let me know what does this line do in my python CODE:

ok so here is the code and i need to know what does this code do when below condition do not match and is there any simpler way to do that,so i can understand it.好的,这是代码,我需要知道当以下条件不匹配时这段代码会做什么,有没有更简单的方法可以做到这一点,所以我可以理解。

major = []
current_major = []
specs={'row': 2, 'exchange': 'NSE', 'name': 'WIPRO', 'token': 969473}
received_token = [969473,415745,12145]

        if specs['token'] not in received_token:
            values = major[[x[0] for x in major].index(name[:-3])]
            current_major.append(values)

            major = current_major
            current_major = []
            #sht2.range('A2').value = major  # using xlwings for live data to excel
            major.append(values)

After your reply in comments, here is what values = major[[x[0] for x in major].index(name[:-3])] is doing.在您回复评论后,这就是values = major[[x[0] for x in major].index(name[:-3])]正在做的事情。

# Case 1
major = [['WI',
        'WR','WW','WK','WI','WL']]
specs={'row': 2, 'exchange': 'NSE', 'name': 'WIPRO', 'token': 969473}
name = specs['name']

values = major[[x[0] for x in major].index(name[:-3])]
print(values)

# Case 2
major = [['WP',
        'WR','WW','WK','WI','WL']]

values = major[[x[0] for x in major].index(name[:-3])]
print(values)

In case 1: You have name[:-3] which is WI in major list hence you get the list major back at that 0 index as output.情况 1:您的name[:-3]major列表中的WI ,因此您在该0索引处获得major列表,即 output。 ( .index() function look for the index of the element in major) .index() function 查找主要元素的索引)
Output: Output:

['WI', 'WR', 'WW', 'WK', 'WI', 'WL']

In case 2: WI is not present in the major hence you get an error:情况 2: WI不存在于major中,因此您会收到错误消息:

ValueError: 'WI' is not in list

暂无
暂无

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

相关问题 我在 python 中创建单元测试时遇到问题。谁能告诉我我的错误是什么? - I am having problem creating a unit test in python. can anyone let me know what's my mistake? 请在以下python代码中让我知道问题 - Please let me know the problem in the following python code 我对镶木地板文件和 python 完全陌生,谁能告诉我如何读取 pyspark 中带有标题的镶木地板文件 - I am completely new to parquet files and python, Can anyone please let me know how to read parquet file with headers in pyspark 任何人都可以帮助我了解这部分 python 代码是什么意思吗? - Can anyone help me with what does this part of python code mean? 谁能向我解释以下代码有什么问题 - Can anyone please explain to me what is wrong with the following code 任何人都可以解释这个python代码如何逐行工作? - Can anyone please explain how this python code works line by line? 您能否让我知道在 selenium python 的浏览器中的网络选项卡中捕获除 200 以外的状态代码的代码吗? - Can you please let me know the code to capture the status codes other than 200 in network tab in browser in selenium python? 有人可以扫描我编写的这段 Python 代码并让我知道我做错了什么吗? - Can someone scan over this Python code that I wrote and let me know what I did wrong? 我可以知道这行特定的代码是什么意思吗,我如何将它放入 Python 的 for 循环中 - Can I know what does this specific line of code means and how do i put it in a for loop in Python IndexError : list index out of range 请让我知道为什么我的代码不起作用 - IndexError : list index out of range Please let me know why isnt my code working
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM