jeudi 3 décembre 2015

same-line iteration through list/string in if statement

In python 3.

a = True
b = 'ab'
letters = 'abcd'
if a and (b[0] in letters or b[1] in letters):
     do sth

Is there a more efficient way to iterate through the string if there are more than 2 elements in b (e.g. b = '5b$"£$$-')?

Thank you

Aucun commentaire:

Enregistrer un commentaire