Is there a way to know the true number in Python Repeat for?

Asked 1 years ago, Updated 1 years ago, 58 views

There's a repeat for If you get the number of numbers that are less than 10 divided by 3, you make the repeat statement like this.

answer = 0
for i in range(10):
    if i%3 == 0:
        answer += 1

return answer

But is there a way to find out the number without specifying a variable?

python loops

2022-09-22 15:41

2 Answers

len(list(filter(lambda i: i%3 == 0, range(10))))
4

len([i for i in range(10) if i % 3 == 0])
4


2022-09-22 15:41

Wouldn't there be a count? I think there's going to be something like length.


2022-09-22 15:41

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.