I have a function which takes a count and a string as input. It should return a list of all words in that string of length count, and greater. Python however doesn't recognise my variable and returns an empty list.
def word_number(count, string):
return re.findall(r'\w{count,}', string)
How do I pass in the variable 'count' so that the function returns words of count and longer?
You can use printf style formatting:
re.findall(r'\w{%s,}' % count, string)
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