Stack Overflow Asked by determindedElixir on November 27, 2021
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?
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])
Answered by Julio González on November 27, 2021
a = [('hello.',0) , ('foji.',0),('you',0)]
print([(s[0].replace('.', ''), s[1]) for s in a])
Output:
[('hello', 0), ('foji', 0), ('you', 0)]
Answered by badhusha muhammed on November 27, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP