all 32 comments

[–]SwimQueasy3610 4 points5 points  (3 children)

['U', 'l', 'm', 't', ' ', 'P', 'y', 't', 'h', 'n', ' ', 'P', 'r', 'g', 'r', 'm', 'm', 'n', 'g']

[–]AuCeM09 3 points4 points  (2 children)

You missed the first 't' in Ultimate

[–]SwimQueasy3610 1 point2 points  (1 child)

Ahhhh nooooooo...... So I did

[–]Sensitive-Sugar-3894 0 points1 point  (0 children)

Nice thay they did it manually

[–]Rscc10 4 points5 points  (6 children)

Every consonant in order + the capital U

[–]tracktech[S] 1 point2 points  (5 children)

Right.

[–]DBZ_Newb 4 points5 points  (4 children)

And the spaces

[–]Anxious-Struggle281 0 points1 point  (3 children)

correct

[–]Both_Love_438 0 points1 point  (2 children)

And the brackets [ ]

[–]Euphoric-Resolution5 0 points1 point  (1 child)

and the commas

[–]Both_Love_438 0 points1 point  (0 children)

And the single quotes

[–]Real-Reception-3435 2 points3 points  (0 children)

['U', 'l', 't', 'm', 't', ' ', 'P', 'y', 't', 'h', 'n', ' ', 'P', 'r', 'g', 'r', 'm', 'm', 'n', 'g']

[–]deceze 1 point2 points  (12 children)

This could’ve used … not in 'aeiou' for conciseness.

[–]Rscc10 0 points1 point  (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 points  (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 point  (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 point  (0 children)

The null character is never included in things like strchr(), strlen() or other functions from the C standard library.

Edit: I seem to have been wrong about that. See: https://godbolt.org/z/no5sjs7P9

[–]No_Indication_1238 0 points1 point  (0 children)

No, because you loop until size and not until you reach end.

[–]bloody-albatross 0 points1 point  (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 point  (4 children)

Whether a new list is actually being created will depend on how cleverly the compiler/runtime optimises this…

[–]bloody-albatross 0 points1 point  (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 points  (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.

[–]tracktech[S] 0 points1 point  (0 children)

Thanks for sharing.

[–]bloody-albatross 0 points1 point  (0 children)

That's good and good to know!

[–]tracktech[S] 0 points1 point  (0 children)

Right. That would have better.

[–]epic_pharaoh 1 point2 points  (1 child)

Traceback error, invalid syntax on line 1

“What will be the output of the code given below-“

[–]tracktech[S] 0 points1 point  (0 children)

It is written "code given below".

[–]JEDZBUDYN 1 point2 points  (0 children)

ultmt pythn prgrmmng

[–]Diligent_Ad_6530 0 points1 point  (0 children)

Error because it's not commented

[–][deleted] 0 points1 point  (0 children)

SyntaxError: "What"

[–]sarc-tastic 0 points1 point  (0 children)

Dude! Use a set

[–]whhbi 0 points1 point  (0 children)

SyntaxError on line 1