Reputation: 13
nums = [i for i in range(1,10000)]
b=[x for x in nums if '7' in x ]
print (b)
TypeError: argument of type 'int' is not iterable
Upvotes: 1
Views: 265
Reputation: 959
nums = [i for i in range(1,100)]
b=[x for x in str(nums) if '7' in x]
print(f'There are {len(b)} numbers that contain the number 7.')
Upvotes: 1
Reputation: 11
nums = [i for i in range(1,10000)]
b=[x for x in nums if '7' in str(x) ]
print (len(b))
print(b)
Upvotes: 1
Reputation: 18426
Create a Boolean generator for the given condition, and call sum
on it, you will get the number of integers that evaluates to be True
for the given condition.
>>>sum('7' in str(i) for i in range(1,10000))
3439
Upvotes: 2