Reputation: 16691
Im trying to do some basic list comprehension such as ...
abc = [1, 11, 123, 124, 1234, 1234, 2323124, 12, 1354, 235, 2345]
[ str(x) for x in abc if "1" in x ]
Can anyone point me in the right direction ?
Upvotes: 0
Views: 112
Reputation: 50995
Like this?:
[str(x) for x in abc if "1" in str(x)]
Of course this will convert each number to a string twice, so it would be more efficient to do something like this:
[x for x in map(str, abc) if "1" in x]
Upvotes: 5