Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
替换列表中的值
列表
a=[5,6,7,5,8,7]
将 7 替换为 3
所需输出
[5,6,3,5,8,7]
健康)状况?
没有切片?
您可以使用列表推导:
[3 if x==7 else x for x in a]