【问题标题】:Need help describing and understanding some python code需要帮助描述和理解一些 python 代码
【发布时间】:2023-04-01 09:52:01
【问题描述】:

如果有人能帮助我理解这个程序中的每一行代码,我将不胜感激。谢谢

sentence = "ASK NOT WHAT YOUR COUNTRY CAN DO FOR YOU ASK WHAT YOU CAN DO FOR YOUR COUNTRY"
s = sentence.split() 
another = [0] 

 print(sentence)
for count, x in enumerate(s): 
    if s.count(x) < 2:
        another.append(max(another) + 1)
    else:
        another.append(s.index(x) +1)
another.pop(0) 

print(another)

【问题讨论】:

  • 您介意拿一本 Python 手册阅读一下吗?
  • 这不是辅导服务。
  • 在每一行之后使用print() 并打印变量,你就会看到这个函数做了什么。
  • 我们可以帮助您解决编码问题,但我们无法为您理解事情
  • 您好,请您在 python 终端中编码,然后您会获得更多想法,请始终尝试理解其他人的代码

标签:
python
python-2.7