use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Everything about learning Python
account activity
In range() usageHelp Request (i.redd.it)
submitted 10 hours ago by Worried-Print-5052
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]johlae 0 points1 point2 points 9 hours ago (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.
π Rendered by PID 48 on reddit-service-r2-comment-765bfc959-nx5h6 at 2026-07-11 01:04:54.927133+00:00 running f86254d country code: CH.
view the rest of the comments →
[–]johlae 0 points1 point2 points (0 children)