Skip to content

stonelouse/learn-python-01

Repository files navigation

Learning Python

References

hartl

  • Hartl, Michael: Learn enough Python to be dangerous, Humble Bundle Pearson, 2023
    Source Code | GitHub

Links

PEP 8

Some Python Doc Sides

Emojis

Notes

Pythonic/ unPythonic programming

Notable differences between Python and most other languages

"Literals" vs. Comprehensions

["ant", "bear", "spider"]                        # Literal list
("ant", "bear", "spider")                        # Literal tuple
{1, 2, 3, 3, 4, 1}                               # Literal set
{"stop": "red", "wait": "yellow", "go": "green"} # Literal dictionary

[]                                               # empty list
()                                               # empty tuple
{}                                               # empty dictionary
set()                                            # empty set

states = ["Kansas", "North Dakota", "Nebraska", "South Dakota"]
# List comprehension ➡️ ['north-dakota', 'south-dakota']
["-".join(state.lower().split()) for state in states if len(state.split()) > 1]

# Dictionary comprehension ➡️ {6: 'Kansas', 8: 'Nebraska'}
{len(state): state for state in states if len(state.split()) == 1}

", ".join(
...   # Generator comprehension ➡️ 'kansas, nebraska'
...   state.lower() for state in states if len(state.split()) == 1
... )

>>> from itertools import chain
>>> list(chain.from_iterable([state.split() for state in states]))
['Kansas', 'North', 'Dakota', 'Nebraska', 'South', 'Dakota']
# Set comprehension
>>> {element for element in list(chain.from_iterable([state.split() for state in states]))}
{'Kansas', 'South', 'Dakota', 'Nebraska', 'North'}

Overview

Chapter 1

Chapter 2 - String Basics

Chapter 3 - Lists

Chapter 4 - Other Native Objects

Chapter 5 - Functions and Iterators

Chapter 6 - Functional Programming

Chapter 7 - Objects and Classes

About

Learning Python

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages