简体   繁体   English

如何在循环中更改值?

[英]How to change value in a loop?

Tell me how to make the value change in the loop when the command is needed:告诉我在需要命令时如何在循环中更改值:

for k, v in sorted(news_dict.items())[-2:-1]

eg always when I give the command "next" should add (-1).例如,当我给出命令“下一步”时,总是应该添加 (-1)。 From [-2:-1] to [-3:-2] then [-4:-3] etc.从 [-2:-1] 到 [-3:-2] 然后 [-4:-3] 等等。

I'd say add another loop that will change these values我会说添加另一个循环来改变这些值

values = sorted(news_dict.items())
for i in range(1, 10):
    for k, v in values[-i - 1:-i]:
        print(k, v)

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

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