Ron Paulfan Ron Paulfan - 1 year ago 99
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'''


Answer Source

Using a list comprehension:

print [x for x in var.split() if len(x) > 20]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download