Search code examples
pythonpython-3.xlisttuplesstrip

How can I delete a specific character from set of tuples?


I want to delete points(".") at the end of every word.

My code looks like this:

a = [('hello.',0) , ('foji.',0),('you',0)]
print([s.strip('.') for s in a])

The output should look something like: [('hello',0) , ('foji',0), ('you',0)]

I get an error says tuple object has no attribute strip! even if i use lists instead i get the same error !

note : using replace doesn't work too.

What should I do to fix this?


Solution

  •   a = [('hello.',0) , ('foji.',0),('you',0)]
      print([(s[0].replace('.', ''), s[1]) for s in a])
     
    

    Output:

      [('hello', 0), ('foji', 0), ('you', 0)]