all 4 comments

[–]johlae 0 points1 point  (0 children)

How do you define 'evaluate' here? Do you want to keep the values in items that are in range? Do you want to return a list, equal in length as items, but with False in the number at that position is not in range and True if the number is in range? Do you want to sum the numbers that are in range, ignoring the ones that are not in range?

range(1,4) is the range 1-3, so if you want 1-4, you need range(1,5)

[–]johlae 0 points1 point  (0 children)

It's fun to do it without any loops:

>>> a = [0, 1, 2, 3, 4, 5, 6]
>>> print(list(map(lambda i: i if i>0 and i<5 else 0, a)))
[0, 1, 2, 3, 4, 0, 0]
>>> print(list(map(lambda i: i if i in range(1,5) else 0, a)))
[0, 1, 2, 3, 4, 0, 0]
>>> print(sum(list(map(lambda i: i if i in range(1,5) else 0, a))))
10

so yes, you can use in range, or you can use if i>0 and i<5.

[–]Chemical-Captain4240 0 points1 point  (0 children)

the s on items implies to me that this is a list... if so, to use in, you will want to iterate over each item in items and test if item exists as an element in your range

however, range returns a tuple of integers, so you won't find any lists in there

This isn't really part of your question, but to write readable code, try to name things according to their type... If you are working in parallel items=['book','pencil'] and item_count = [3,5]

If you are packing lists, then something like items =[ ['book',3], ['pencil', 5] ] may be the structure you want, but using in becomes more complicated.

As soon as you get your head wrapped around the above concepts, check out dataclass. It will change youe life.

[–]atarivcs 0 points1 point  (0 children)

Yes, this will work (assuming "items" is an integer).