vikky 2405 vikky 2405 - 1 year ago 103
Python Question

How to replace a dot with a string in a python list

my_list = ['b','.','.']

expected_list = ['b','.','w']

May be simple, moving into python recently so any suggestions would be fine

Answer Source

If you are replacing every occurrence of '.' with 'w' then I would just suggest:

for n, i in enumerate(my_list):
    if i == '.':
        my_list[n] = 'w'

Here is the documentation for how to use the enumerate() function:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download