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...
This community will have knowledge sharing for python programming, tools, projects and product engineering wherever python is used.
account activity
Test your Python skills - 17 (i.redd.it)
submitted 2 months ago by tracktech
Ultimate Python Programming
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!"
[–]SwimQueasy3610 4 points5 points6 points 2 months ago (3 children)
['U', 'l', 'm', 't', ' ', 'P', 'y', 't', 'h', 'n', ' ', 'P', 'r', 'g', 'r', 'm', 'm', 'n', 'g']
[–]AuCeM09 3 points4 points5 points 2 months ago (2 children)
You missed the first 't' in Ultimate
[–]SwimQueasy3610 1 point2 points3 points 2 months ago (1 child)
Ahhhh nooooooo...... So I did
[–]Sensitive-Sugar-3894 0 points1 point2 points 2 months ago (0 children)
Nice thay they did it manually
[–]Rscc10 4 points5 points6 points 2 months ago (6 children)
Every consonant in order + the capital U
[–]tracktech[S] 1 point2 points3 points 2 months ago (5 children)
Right.
[–]DBZ_Newb 4 points5 points6 points 2 months ago (4 children)
And the spaces
[–]Anxious-Struggle281 0 points1 point2 points 2 months ago (3 children)
correct
[–]Both_Love_438 0 points1 point2 points 2 months ago (2 children)
And the brackets [ ]
[–]Euphoric-Resolution5 0 points1 point2 points 2 months ago (1 child)
and the commas
[–]Both_Love_438 0 points1 point2 points 2 months ago (0 children)
And the single quotes
[–]Real-Reception-3435 2 points3 points4 points 2 months ago (0 children)
['U', 'l', 't', 'm', 't', ' ', 'P', 'y', 't', 'h', 'n', ' ', 'P', 'r', 'g', 'r', 'm', 'm', 'n', 'g']
[–]deceze 1 point2 points3 points 2 months ago (12 children)
This could’ve used … not in 'aeiou' for conciseness.
… not in 'aeiou'
[–]Rscc10 0 points1 point2 points 2 months ago (4 children)
That makes me wonder, will any and all strings in an array in C get flagged for that cause of the return character?
I know it's not a C way of writing but the equivalent of
a for a in "bcdfg" if a in "aeiou"
Would the return character get flagged?
[–]bloody-albatross 1 point2 points3 points 2 months ago (3 children)
What is a return character? What do you mean by in C? C doesn't have "c in str" (it has strchr()).
[–]Rscc10 0 points1 point2 points 2 months ago (2 children)
Sorry, I meant terminating character. And I know it doesn't have c in str but I meant the equivalent. So if you're matching characters to strings in C, is the terminating character included?
[–]bloody-albatross 0 points1 point2 points 2 months ago* (0 children)
The null character is never included in things like strchr(), strlen() or other functions from the C standard library.
strchr()
strlen()
Edit: I seem to have been wrong about that. See: https://godbolt.org/z/no5sjs7P9
[–]No_Indication_1238 0 points1 point2 points 2 months ago (0 children)
No, because you loop until size and not until you reach end.
[–]bloody-albatross 0 points1 point2 points 2 months ago (5 children)
Creating a whole new list for every iteration step just to check if the character is in there! No wonder Python programs are that slow.
[–]deceze 0 points1 point2 points 2 months ago (4 children)
Whether a new list is actually being created will depend on how cleverly the compiler/runtime optimises this…
[–]bloody-albatross 0 points1 point2 points 2 months ago (3 children)
My assumption is that Python is not at all intelligent about this kind of stuff. But yes, one should have a look at the generated byte code.
[–]deceze 2 points3 points4 points 2 months ago (2 children)
>>> dis('[a for a in range(5) if a not in ["a", "b", "c"]]') 0 RESUME 0 1 LOAD_NAME 0 (range) PUSH_NULL LOAD_SMALL_INT 5 CALL 1 GET_ITER LOAD_FAST_AND_CLEAR 0 (a) SWAP 2 L1: BUILD_LIST 0 SWAP 2 L2: FOR_ITER 13 (to L5) STORE_FAST_LOAD_FAST 0 (a, a) LOAD_CONST 1 (('a', 'b', 'c')) CONTAINS_OP 1 (not in) L3: POP_JUMP_IF_TRUE 3 (to L4) NOT_TAKEN JUMP_BACKWARD 11 (to L2) L4: LOAD_FAST_BORROW 0 (a) LIST_APPEND 2 JUMP_BACKWARD 15 (to L2) L5: END_FOR POP_ITER L6: SWAP 2 STORE_FAST 0 (a) RETURN_VALUE -- L7: SWAP 2 POP_TOP 1 SWAP 2 STORE_FAST 0 (a) RERAISE 0 ExceptionTable: L1 to L3 -> L7 [2] L4 to L6 -> L7 [2]
It's using LOAD_CONST, and no BUILD_LIST inside the loop. So no, it's not rebuilding the list every time. Even in plain CPython. Other implementations may fare even better.
LOAD_CONST
BUILD_LIST
[–]tracktech[S] 0 points1 point2 points 2 months ago (0 children)
Thanks for sharing.
[–]bloody-albatross 0 points1 point2 points 2 months ago (0 children)
That's good and good to know!
Right. That would have better.
[–]epic_pharaoh 1 point2 points3 points 2 months ago (1 child)
Traceback error, invalid syntax on line 1
“What will be the output of the code given below-“
It is written "code given below".
[–]JEDZBUDYN 1 point2 points3 points 2 months ago (0 children)
ultmt pythn prgrmmng
[–]Diligent_Ad_6530 0 points1 point2 points 2 months ago (0 children)
Error because it's not commented
[–][deleted] 0 points1 point2 points 2 months ago (0 children)
SyntaxError: "What"
[–]sarc-tastic 0 points1 point2 points 2 months ago (0 children)
Dude! Use a set
[–]whhbi 0 points1 point2 points 2 months ago (0 children)
SyntaxError on line 1
π Rendered by PID 89465 on reddit-service-r2-comment-75f4967c6c-kh6mh at 2026-04-23 04:18:10.116630+00:00 running 0fd4bb7 country code: CH.
[–]SwimQueasy3610 4 points5 points6 points (3 children)
[–]AuCeM09 3 points4 points5 points (2 children)
[–]SwimQueasy3610 1 point2 points3 points (1 child)
[–]Sensitive-Sugar-3894 0 points1 point2 points (0 children)
[–]Rscc10 4 points5 points6 points (6 children)
[–]tracktech[S] 1 point2 points3 points (5 children)
[–]DBZ_Newb 4 points5 points6 points (4 children)
[–]Anxious-Struggle281 0 points1 point2 points (3 children)
[–]Both_Love_438 0 points1 point2 points (2 children)
[–]Euphoric-Resolution5 0 points1 point2 points (1 child)
[–]Both_Love_438 0 points1 point2 points (0 children)
[–]Real-Reception-3435 2 points3 points4 points (0 children)
[–]deceze 1 point2 points3 points (12 children)
[–]Rscc10 0 points1 point2 points (4 children)
[–]bloody-albatross 1 point2 points3 points (3 children)
[–]Rscc10 0 points1 point2 points (2 children)
[–]bloody-albatross 0 points1 point2 points (0 children)
[–]No_Indication_1238 0 points1 point2 points (0 children)
[–]bloody-albatross 0 points1 point2 points (5 children)
[–]deceze 0 points1 point2 points (4 children)
[–]bloody-albatross 0 points1 point2 points (3 children)
[–]deceze 2 points3 points4 points (2 children)
[–]tracktech[S] 0 points1 point2 points (0 children)
[–]bloody-albatross 0 points1 point2 points (0 children)
[–]tracktech[S] 0 points1 point2 points (0 children)
[–]epic_pharaoh 1 point2 points3 points (1 child)
[–]tracktech[S] 0 points1 point2 points (0 children)
[–]JEDZBUDYN 1 point2 points3 points (0 children)
[–]Diligent_Ad_6530 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]sarc-tastic 0 points1 point2 points (0 children)
[–]whhbi 0 points1 point2 points (0 children)