Jacques Anthony Jacques Anthony - 9 days ago 7
Python Question

How to remove commas and dots of individual word in two dimensional list?

Sorry, I am a beginner in learning Python so, I was complicated while trying to remove commas and dots of individual word in two dimensional list.

For example, I have:

list = [ ['Hello.', 'My', 'World,'] ]


Desired list:

desired_list = [ ['Hello', 'My', 'World'] ]


Thanks for Help!

Answer

Try with my solution:

list = [['Hello.', 'My', 'World,']]

list_n = []
for l in list:
    n = []
    for e in l:
        e = e.replace('.', '')
        e = e.replace(',', '')
        n.append(e)
    list_n.append(n)

print(list_n)

Output:

[['Hello', 'My', 'World']]