0

I'd like to simply know if this does not lead the program to errors.

for a in b:
    if <condition>:
        b = b + [something]
Tristran Thorn
  • 91
  • 1
  • 3
  • 5
  • 4
    why dont you try this? – Vishnu Upadhyay Nov 06 '14 at 13:56
  • FWIW: You are not "appending". You're creating a new list from the combination of `b` and `[something]`. – sebastian Nov 06 '14 at 14:00
  • 1
    possible duplicate of [Modifying list while iterating](http://stackoverflow.com/questions/1637807/modifying-list-while-iterating) (Assuming you really want to append, instead of recreating a new list) – sebastian Nov 06 '14 at 14:04
  • `b[:] = b + [x]` would modify the original list and also create an infinite loop `for x in b[:]:b[:] = b + [something]` would do what you want but so would extend – Padraic Cunningham Nov 06 '14 at 14:08
  • What data are you trying to act upon? you are taking and element from the list but not using it for anything. – Gaurav Aradhye Nov 06 '14 at 14:47

0 Answers0