determindedElixir
determindedElixir

Reputation: 87

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?

Upvotes: 0

Views: 85

Answers (2)

Julio González
Julio González

Reputation: 71

You are working with tuples inside the list so every element is (element1,element2) change your print to

print([(s[0].strip('.'),s[1]) for s in a])

Upvotes: 3

badhusha muhammed
badhusha muhammed

Reputation: 491

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

Output:

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

Upvotes: 3

Related Questions