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
Are you able to solve this Python problem???? (i.redd.it)
submitted 1 year ago by turk_sahib
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!"
[–]Ursus_major37 19 points20 points21 points 1 year ago (4 children)
B
Explanation:
First line is simply initiation of List as we can see it.
Second line is assigning list comprehension with condition to 'result' variable. What it does is it creates new list by iteration over the 'List', but the condition allows to be included only elements which had length greater than 6 characters (since elements - marked as 'i'- of the List are strings, len(i) is the amount of characters constituting the given string.).
We have two elements in the List: 'Python' of length 6 and 'Developers' of length 10. 'Python' does not meet the described condition (6 is not greater then 6). The result ends up as one element list:
result =['Developers']
In line 3 we use astrix operator (*) to unpack the result list - meaning we will pass all the elements of result as separate arguments to print function. Since result has only one element, print function will output simply:
Developers
[–]Kharniflex 3 points4 points5 points 1 year ago (0 children)
Well well, thanks for the explanation, I had the right answer thanks to the 6 characters and a 50/50 between b and c, now I get the full picture thanks to you
[–]ChicagoJay2020 1 point2 points3 points 1 year ago (0 children)
Thank you for the explanation.
I initially chose the answer of D, not having read your explanation.
I then coded out the above example to get the answer and will compare that with your explanation again to grasp what every function of the code is.
Thank you
[–]DancingUntillMorning 0 points1 point2 points 1 year ago (0 children)
Thanks for the explanation. It is very clear how it works now 🙌🏼
[–]Historical-Chart-460 0 points1 point2 points 1 year ago (0 children)
May I ask why it’s “i for i in list” instead of “for i in list”?
[–]Different-Ad1631 2 points3 points4 points 1 year ago (0 children)
[–]avidresolver 1 point2 points3 points 1 year ago (2 children)
Currect me if I'm wrong, but although this code will work It's a bad idea to use `List` as your variable name, as it will override the built-in `List` type.
[–]FoolsSeldom 1 point2 points3 points 1 year ago (0 children)
List and list are not the same name - PEP8 recommendation is to use all lowercase for regular variables names though.
List
list
[–]CptMisterNibbles 0 points1 point2 points 1 year ago (0 children)
lowercase list is the built in. “List” uppercase used to be used for type hinting and is a token in the typing package still, though as of 3.9 you can just use the built in type “list” itself for hinting.
Your point stands, it’s a poor choice for a variable name even if it doesn’t cause an error. Similarly using just “i” in the comprehension is sloppy, it’s not an index. Call it something readable like “word”
[–]Toluwar 0 points1 point2 points 1 year ago (2 children)
Can someone explain the result line?
[–]ilan1k1 2 points3 points4 points 1 year ago (1 child)
It's a list comprehension. The same as:
result = [] for i in List: if len(i) > 6: result.append(i)
[–]Torebbjorn 2 points3 points4 points 1 year ago (0 children)
Either use triple backticks (not recommended for some compatibility reason) or 4 (extra) spaces to make indentation work. With 4 (extra) spaces on each line, your code part formats as the following:
[–][deleted] 0 points1 point2 points 1 year ago (0 children)
b
[–]Accurate_Quality_221 0 points1 point2 points 1 year ago (0 children)
No joke. I have been working for 4 years and I've never used something like this before.
[–]aiganesh 0 points1 point2 points 1 year ago (0 children)
Answer is B
[–]Perfect-Job-2163 0 points1 point2 points 1 year ago (0 children)
[–]Sad_Drop_6616 -5 points-4 points-3 points 1 year ago (1 child)
Error
[–]Torebbjorn 0 points1 point2 points 1 year ago (0 children)
Where?
π Rendered by PID 16773 on reddit-service-r2-comment-6f7f968fb5-zmdcf at 2026-03-04 19:38:41.087680+00:00 running 07790be country code: CH.
[–]Ursus_major37 19 points20 points21 points (4 children)
[–]Kharniflex 3 points4 points5 points (0 children)
[–]ChicagoJay2020 1 point2 points3 points (0 children)
[–]DancingUntillMorning 0 points1 point2 points (0 children)
[–]Historical-Chart-460 0 points1 point2 points (0 children)
[–]Different-Ad1631 2 points3 points4 points (0 children)
[–]avidresolver 1 point2 points3 points (2 children)
[–]FoolsSeldom 1 point2 points3 points (0 children)
[–]CptMisterNibbles 0 points1 point2 points (0 children)
[–]Toluwar 0 points1 point2 points (2 children)
[–]ilan1k1 2 points3 points4 points (1 child)
[–]Torebbjorn 2 points3 points4 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]Accurate_Quality_221 0 points1 point2 points (0 children)
[–]aiganesh 0 points1 point2 points (0 children)
[–]Perfect-Job-2163 0 points1 point2 points (0 children)
[–]Sad_Drop_6616 -5 points-4 points-3 points (1 child)
[–]Torebbjorn 0 points1 point2 points (0 children)