Skip to content

GREAT list of python tips - I found a few typographical errors and fixed them #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ Python 3.
- 2. Move complex expressions into helper functions, especially if you need to
use the same logic repeatedly.
- 3. The if/else expression provides a more readable alternative to using
Boolean operators like or and adn in expressions.
Boolean operators like or and and in expressions.


### [Item 5: Know hot to slice sequences](item_05_slice_sequence.py)
### [Item 5: Know how to slice sequences](item_05_slice_sequence.py)
- 1. Avoid being verbose: Don't supply 0 for the start index or the length of
the sequence for the end index.
- 2. Slicing is forgiving of start or end indexes that are out of bounds,
Expand All @@ -61,7 +61,7 @@ Python 3.
indexes. Avoid negative stride values if possible.
- 3. Avoid using start, end and stride together in a single slice. If you need
all three parameters, consider doing two assignments (one to slice,
another to stride) or using islice form itertools built-in module.
another to stride) or using islice from itertools built-in module.


### [Item 7: Use list comprehensions instead of map and filter](item_07_list_not_map_filter.py)
Expand Down Expand Up @@ -454,7 +454,7 @@ Python 3.
- 2. Don't re-implement this functionality yourself. It's hard to get right.


### [Item 47: Use decimal when precision ia paramount](item_47_use_decimal.py)
### [Item 47: Use decimal when precision is paramount](item_47_use_decimal.py)
- 1. Python has built-in types and classes in modules that can represent
practically every type of numerical value.
- 2. The Decimal class is ideal for situations that require high precision and
Expand Down Expand Up @@ -493,7 +493,7 @@ Python 3.
that contains other source files. These files become that child modules
of the directory's package. Package directories may also contain other
packages.
- 3. You can provide an explict API for a module by listing its publicly
- 3. You can provide an explicit API for a module by listing its publicly
visible name in its __all__ special attribute.
- 4. You can hide a package's internal implementation by only importing public
names in the package's __init__.py file or by naming internal-only
Expand Down Expand Up @@ -553,7 +553,7 @@ Python 3.
- 2. Calling repr on built-in Python types will produce the printable string
version of a value. These repr strings could be passed to the eval
built-in function to get back the original value.
- 3. %s in format strings will produce human-readable strings like str.%r will
- 3. %s in format strings will produce human-readable strings like str. %r will
produce printable strings like repr.
- 4. You can define the __repr__ method to customize the printable
representation of a class and provide more detailed debugging
Expand Down
4 changes: 2 additions & 2 deletions item_01_version_of_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# readability (type import this).

# Programmers familiar with other language may try to write Python as if it's
# C++, Java, or whatever know best. New programmers may still be getting
# C++, Java, or whatever they know best. New programmers may still be getting
# comfortable with the vast range of concepts expressible in Python. It's
# important for everyone to know the best--the Pythonic--way to do the most
# common things in Python. These patterns will affect every program you write.
Expand All @@ -37,7 +37,7 @@

# Things to Remember

# 1. There are two major version of Python still in active use: Python 2 and
# 1. There are two major versions of Python still in active use: Python 2 and
# Python 3.
# 2. There are multiple popular runtimes for Python: CPython, Jython,
# IronPython, PyPy, etc.
Expand Down
2 changes: 1 addition & 1 deletion item_02_PEP8Style.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# Naming: PEP 8 suggests unique styles of naming for different part in the
# language.

# 1. Functions, variables, and attributs should be in lovercase_underscore
# 1. Functions, variables, and attributes should be in lowercase_underscore
# format.
# 2. Protected instance attributes should be in _leading_underscore format.
# 3. Private instance attributes should be in __double_leading_underscore
Expand Down
4 changes: 2 additions & 2 deletions item_03_Difference_bytes_str_unicode.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
# When you're writing Python programs, it's important to do encoding and
# decoding of Unicode at the furthest boundary of your interfaces. The core of
# your program should use Unicode character types (str in Python 3, unicode in
# Python 2) and should not assume any thing about character encodings. This
# Python 2) and should not assume anything about character encodings. This
# approach allows you to be very accepting of alternative text encodings
# (such as Latin-1, Shift JIS, and Big5) while being strict about your output
# text encoding (idealy, UTF-8).
# text encoding (ideally, UTF-8).

# The split between character types leads to two common situations in Python
# code:
Expand Down
2 changes: 1 addition & 1 deletion item_05_slice_sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# access a subset of a sequence's items with minimal effort. The simplest uses
# for slicing are the built-in types list, str, and bytes. Slicing can be
# extended to any Python class that implements the __getitem__ and __setitem__
# special methods (see Item 28: Inherit form collections.abc for custom
# special methods (see Item 28: Inherit from collections.abc for custom
# container types).

# The basic form of the slicing syntax is somelist[start:end], where start is
Expand Down
4 changes: 2 additions & 2 deletions item_06_avoid_using.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# ['orange', 'green', 'purple']


# The problem is that the stride syntax ofter cause unexpected behavior that
# The problem is that the stride syntax often cause unexpected behavior that
# can introduce bugs. For example, a common Python trick for reversing a byte
# string is to slice the string with a stride of -1.

Expand Down Expand Up @@ -103,4 +103,4 @@
# indexes. Avoid negative stride values if possible.
# 3. Avoid using start, end and stride together in a single slice. If you need
# all three parameters, consider doing two assignments (one to slice,
# another to stride) or using islice form itertools built-in module.
# another to stride) or using islice from itertools built-in module.
2 changes: 1 addition & 1 deletion item_07_list_not_map_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
# [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]


# Unlike may, list comprehensions let you easily filter items from the input
# Unlike map, list comprehensions let you easily filter items from the input
# list, removing corresponding outputs from the result. For example, say you
# only want to compute the squares of the numbers that are divisible by 2.
# Here, I do this by adding a conditional expression to the list
Expand Down