Skip to content
Advertisement

How do I find countries where the name has between 4 and 5 letters with regex in python list?

How can I generate a list with regex in python for countries with 4 or 5 letters?

JavaScript

I was trying to do this but it returns an empty list:

JavaScript

It is an exercise that’s why I can only do it with the module re. Any help will be appreciate.

Advertisement

Answer

You can use len(w).

JavaScript

But if you want to solve it with regex you can use re.search and If maybe you have numbers in list you can use walrus operator (:=) for python >= 3.8

JavaScript

For python < 3.8 you can use try/except.

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement