[(',', 52),
('news', 15),
('.', 11),
('bbc', 8),
('and', 8),
('the', 8),
(':', 6),
('music', 5),
('-', 5),
('blog', 4),
('world', 4),
('asia', 4),
('international', 4),
('on', 4),
('itunes', 4),
('online', 4),
('digital', 3)]
Suppose I have this list, with tuples inside.
How do I go through the list and remove elements that don't have alphabetical characters in them?
So that it becomes this:
[('news', 15),
('bbc', 8),
('and', 8),
('the', 8),
('music', 5),
('blog', 4),
('world', 4),
('asia', 4),
('international', 4),
('on', 4),
('itunes', 4),
('online', 4),
('digital', 3)]
the_list = [(a, b) for a, b in the_list if a.isalpha()]
Easiest should be a list comprehension with a regular expression:
import re
lst = [...]
lst = [t for t in lst if re.search(r'\w', t[0])]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With