How to modify list entries during for loop?

前端 未结 9 720
旧巷少年郎
旧巷少年郎 2020-11-22 01:56

Now I know that it is not safe to modify the list during an iterative looping. However, suppose I have a list of strings, and I want to strip the strings themselves. Does re

9条回答
  •  难免孤独
    2020-11-22 02:14

    One more for loop variant, looks cleaner to me than one with enumerate():

    for idx in range(len(list)):
        list[idx]=... # set a new value
        # some other code which doesn't let you use a list comprehension
    

提交回复
热议问题