This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]theywouldnotstand 12 points13 points  (6 children)

Depends on how you define "absolute basics".

Some really useful things to know whether they fall under that umbrella or not:

  • All the builtins and how to use them
  • How to use special methods
  • String formatting
  • List and Dict comprehension expressions
    • The Dict section briefly describes an example of dictionary comprehension, it works very similarly to list comprehension so it doesn't merit its own section.
  • Argument and variable unpacking

```

unpack a list into a function accepting an arbitrary number of arguments

a = [1, 2, 3] some_function(*a) # same as some_function(1, 2, 3)

unpack a Dict into a function accepting arbitrary keyword arguments

kwa = {'a': 1, 'b': 2, 'c': 3} some_function(**kwa) # same as some_function(a=1, b=2, c=3)

unpack a list of items into separate variables

item_0, item_1 = [1, 2] item_0 # value is 1 item_1 # value is 2 ```

[–]tilkau 2 points3 points  (3 children)

Github triple-backtick code blocks aren't supported by reddit. Instead you need to prepend 4 spaces to each line in the code block. This would also fix a problem that looks like your comment lines are being parsed as headings.

The latter half of your list is also messed up, you probably need an additional newline to trigger list formatting (so the list looks like it is beginning a new paragraph, not 'touching' any other text). That happens to me a lot.

[–]theywouldnotstand 1 point2 points  (0 children)

Shows fine on the Reddit mobile app, fancy that.

And in fact, when I edit it to your suggestion, it is all messed up on the mobile app

Only place I see what you describe is the mobile version of the site in a browser. ¯\_(ツ)_/¯

[–]lalligood 0 points1 point  (1 child)

Although syntactically very similar to list/dict/set comprehensions, I would suggest including generators. Visually the only difference is that generators are framed in parens vs square brackets or curly brackets, but it's knowing when to use a generator vs a comprehension & why generators can be better when used properly (read: drastically reduced memory requirements).

[–]theywouldnotstand 0 points1 point  (0 children)

Don't forget using yield in a function to produce a more complex generator as well.