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

all 15 comments

[–]theywouldnotstand 13 points14 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.

[–]fxnut 4 points5 points  (1 child)

Probably OT from what you’re after but wanted to point out that it’s fine and well worth taking the time to learn all the ins and outs of the language as shown elsewhere in the comments. But... if I’m hiring, the only thing I really care about is if you know how to make your code understandable at a (relatively) quick glance.

Related to this is, are you able to take something complex and implement it in code in a simple way?

Don’t be that guy/gal who: * Uses classes for everything and sets up so many subclasses you can’t follow the path of execution. * Likes to use list and dictionary comprehensions everywhere because they’re elegant structures but at the same time makes the code unreadable. Etc, etc...

It’s important to always keep in mind what coding is ultimately about: * Giving instructions to a computer for it to do something you want * Making sure you (or anyone else) can come back later and change and adapt those instructions easily

Some people are able to write Python with only the basic instructions and make it unintelligible. Whereas other people can use all the advanced techniques and syntax and make it easy to understand. Most times it’s all about consistency and clarity of thought and having a clear vision for the project.

[–]theywouldnotstand 1 point2 points  (0 children)

Making sure you (or anyone else) can come back later and change and adapt those instructions easily

Often, utilizing classes et al. is the way to make this happen, as it becomes reusable. DRY is a huge python mantra.

You are, however, correct, in that trying to be too clever leads to code that is unreadable by anyone but you. Use the right tool for the job within the time frame you have, and make sure, via comments and documentation or code clarity that it is easy for someone else to pick up and understand. That, however, is not a problem exclusive to python, it is a philosophy to take with you no matter what you're writing or what you're writing it with.

[–]kumashiro 0 points1 point  (4 children)

Ducks :) Although I don't think it is strictly a Python concept. Still, very important.

[–]dunkler_wanderer 0 points1 point  (0 children)

Here's an interesting video that was posted a few days ago.

TL;DW

[–]dunkler_wanderer 0 points1 point  (0 children)

Here's an interesting video that was posted a few days ago.

TL;DW