-1

If possible, why the code below is invalid? (to get [2,2,4,5]):

tsil=[1,2,3,4]
added=[i+1 if i!=2 else i=2 for i in tsil]

Is there an inbuilt way of leaving a certain element (ex: all the "2"s) unchanged without skipping them?

Stop harming Monica
  • 12,141
  • 1
  • 36
  • 56
Ashkan Ek
  • 3
  • 1

1 Answers1

0
tsil=[1,2,3,4]
added=[i+1 if i!=2 else 2 for i in tsil]
vBrail
  • 181
  • 10