Multiple assignment with * and ** - Deepstash

Bite‑sized knowledge

to upgrade

your career

Ideas from books, articles & podcasts.

Multiple assignment with * and **

the * prefix operator was added to the multiple assignment syntax, allowing us to unpack the remaining items in an iterable.

The ** operator does something similar, but with keyword arguments. The ** operator allows us to take a dictionary of key-value...

STASHED IN:

1

MORE IDEAS FROM THE SAME ARTICLE

I love the zip function and it has saved me countless (nested) loops. I use it mostly for iterating over two data types at the same time, where I need the indexes to be equal.

You can do this with any data type or generator. For instance, you could create dictionaries without l...

Dictionaries are great data-types for storing values with an attribute field known as the key , in so-called key-value pairs . When extracting key-value pairs from dictionaries, avoid running into KeyError exceptions with the .get m...

Unpacking variables are probably most used for functions that return multiple variables, such as in the example below.

But it is also useful for data types that contain multiple items. The only important notion here is that, if not otherwise defined, variable unpacking results in tupl...

Making your Python code as re-usable as possible should be one of your main concerns. But what if you’re working on a Unix platform and your colleague is working on Windows?

The path delimiter on Windows is \ , but on my Linux or Mac system, it is / . Avoid dealing...

List, tuple, and dictionary comprehensions are ways to code more efficiently: do the same in fewer lines of code.

Both lines 2-4 and lines 13-15 are compressed in single-line expressions in line 6 and line 17 . This saves up unnecessary lo...

Hallelujah! That is what I thought when I learned about the Python 3.6+ update that includes a new way of formatting strings: the Python formatted string literal. String formatting in Python has come a long way.

F-strings consider everything within { curly brackets } as an ...

IDEA ABOUT

Discover and save more ideas by creating a

FREE

Deepstash account.

Develop a

reading habit

, save

time

and create an amazing

knowledge library

.

GET THE APP:

MORE LIKE THIS

  • Built-in fast webserver
  • Production-ready
  • Highly scalable
  • ASGI compliant
  • Simple and intuitive API design
  • By the community, for the community

STASHED IN:

2

published 3 ideas

Goal: To provide a simple way to get up and running a high-performance HTTP server that is easy to build, expand, and ultimately to scale.

0 Comments

Power of python recursion

Recursive function for calculating n! implemented in Python:

Behind the scenes, each recursive call adds a stack frame (containing its execution context) to the call stack until we reach the base case. Then, the stack begins to unwind as each call returns its results:

A d...

2

STASHED IN:

5

1. Use a Coding Standard

It’s easy to write bad, unorganized code, but it’s hard to maintain such code. Good code typically follows some standard for naming conventions, formatting, etc. Such standards are nice because they make things deterministic to those who read your code afterwards, including yourself. Use somethin...

3

STASHED IN:

7