How to Replace Items in a Python List
You can use a list comprehension to replace items in a Python list: Copy my_list = [‘item 1’, ‘item 2’, ‘item 3’,…] my_list = [‘new item’ if i==’old item’ else i for i in my_list] To better understand how to replace items in a Python list, you’ll see the following 3 scenarios about: Replacing an … Read more