Useful Python Idioms, Recipes, and snippets
Python
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
advanced
.gitignore
README.md
are_two_lists_similar.py
blocks_from_sequence.py
check_if_string_is_permutation.py
comprehensions.py
creating_dictionaries.py
file_io.py
grouping.py
is_palindrome.py
is_string_in_string_list.py
longest_line_in_file.py
loop_backwards.py
loop_collection_and_indices.py
loop_in_sorted_order.py
ordered_iterable.py
pairwise_iteration.py
reverse_sliceable.py
reverse_words.py
sum_of_digits.py
tracking_index_with_iterable.py
unique_elements.py

README.md

Python-Idioms

Useful Python Idioms, Recipes, and snippets.

Note: These apply mainly to python 3.x as they are built using that version.

This means that either:

  1. An entry will work on 2.7.x
  2. An entry will fail on 2.7.x
  3. An entry won't be efficient on 2.7.x (such as using range vs xrange)
  4. Something I haven't thought of

I try to use the standard library for the majority of my work so most of these will be based off of what is available to everyone who has installed python.

My version: 3.3.2

Resources

Raymond Hettinger's Twitter

Useful Python Videos

Python Standard Library Documentation Stack Overflow