drsealks
drsealks

Reputation: 2354

Determine if the string contains any currency sign?

How can I find out if some string contains any currency sign? Say, I need a function that returns 1 if a string contains any currency sign(USD,GBP,RUR,etc) and 0 - otherwise

321->0
$32->1
34$->1

Is there a way to do it easily in python?

Thank you.

Upvotes: 2

Views: 2234

Answers (1)

jonrsharpe
jonrsharpe

Reputation: 122142

You could make your own function, e.g.:

def any_curr(s, curr="¥$€£"):
    return any(c in s for c in curr)

This returns True or False.

You can supply either a string of characters to check or an iterable of strings, e.g.

>>> any_curr("EUR250", ["USD", "GBP", "EUR"])
True

Upvotes: 10

Related Questions