Skip to content
Advertisement

Change multiple items in a list at one time in Python

Can I change multiple items in a list at one time in Python?

Question1: For example,my list is

JavaScript

I want to the third and fifth item become 99.I know I can do it by

JavaScript

However, is there any easier way to do this?

Question2:in the situation,my target value is[99,98], my index is [2,4],so my result would be [0,0,99,0,98]. Is there any easy way to do this? Thanks.

Advertisement

Answer

You could do like this,

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement