Ron Paulfan Ron Paulfan - 3 months ago 14
Python Question

Find string greater than (x) in length

How can I search through a variable and look for a word/string that is greater than 20 in length?

var = '''this is my example and I want
no find the following
string jakjajsiwjsjwijaksjdfjaiwjalskdjfiajwlajfklajsdfwi
from this variable'''


Thanks

Answer

Using a list comprehension:

print [x for x in var.split() if len(x) > 20]