Skip to main content
 首页 » 编程设计

python之将当前项目与 python 列表中的下一个项目进行比较

2025年05月04日8kevingrace

<分区>

考虑一个 python 列表,我如何比较当前项目和下一个项目?例如:

mylist = [1, 2, 2, 4, 2, 3] 
for i in mylist:         
    if i == next item: 
       replace (both i and next item) with "same value" 
 
 >>> [1, "same value", "same value", 4, 2, 3]