Want a ToC? View at http://j.mp/importantPy
http://j.mp/python30 - Why Python? What’s in Python? Where in Python? All in 30 minutes!
http://j.mp/howToThinkLikeAProgrammer - 7 very clear steps / tactics that must become second nature to you.
What to build using Python? http://j.mp/pythonApps of course!
Python and puzzles - http://j.mp/puzzlesPythonMIT
Part of the MITx commitment to open learning is focused on making MOOCs accessible to learners with disabilities. MITx learner Aditi Shah is a young woman in India with goals to create the next generation of cyber security tools. She’s also blind.
Aditi was able to independently complete our set of introductory computer science courses. She could do this without sighted assistance because MITx considers how a blind person accesses and demonstrates mastery of a subject. Now she’s moving on to a Master’s degree program and advancing in her career.
-
- Read her inspiring story - http://j.mp/aditiMITPython
Useful CheatSheet - https://gto76.github.io/python-cheatsheet/
https://www.quora.com/What-are-commonly-asked-Python-interview-questions
https://danieltakeshi.github.io/2013/07/05/ten-things-python-programmers-should-know/
Top links
https://www.quora.com/How-should-I-start-learning-Python-1?redirected_qid=907
https://www.quora.com/What-is-an-ideal-checklist-to-learn-Python-in-30-days/answer/Janarthanan-S-1?srid=ul6v - explore Python in 30 days
http://j.mp/python4Months - and http://blog.agupieware.com/2014/01/benchmarks-teach-yourself-python-in.html
http://bit.ly/beginnerPython - easy video tutorials including for unittesting - http://j.mp/unittestVideo
Learn by Doing (#6) - #6 Learn by doing: practice your programming skills and build real projects as soon as possible.
Table of Contents
What’s new in Python 3? Read this
In Python, there are iterables and there are non-iterables. Which of the following is not an iterable?
'abcdef'
range(100)
[1, 2, 3, 4, 55, 100]
[('a', 1), ('b', 2), ('c', 33)]
(('a'), ('b'), ('c'), ('a', 1), ('b', 2), ('c', 33))
zip(string.ascii_lowercase, range(26))
adict.keys()
where adict
is a Python dictionary variableadict.values()
where adict
is a Python dictionary variable{'a': 1, 'b': 2, 'c':3}
set(string.ascii_lowercase)
[[1, 2], [3], [4, 5, 6], [0]]
There are 4 main types in Python (string, tuples, list and dictionary). And across all of them, there are about 25 important attributes (methods) that help process/modify them. They are tabulated as follows:
Type | Attributes |
---|---|
__builtins__ |
int , str , tuple , list , dict , len , sorted , del |
<class 'str'> |
capitalize , 1 count , endswith , 2 find , format , index , isalnum , 3 isalpha , isdecimal , isdigit , islower , isnumeric , isspace , istitle , isupper , 4 join , ljust , lower , lstrip , replace , 5 rfind , rindex , rjust , 6 split , splitlines , startswith , 7 strip , swapcase , title , upper , zfill |
<class 'tuple'> |
8 count , index |
<class 'list'> |
9 append , clear , copy , 10 count , 11 extend , index , 12 insert , 13 pop , 14 remove , 15 reverse , 16 sort |
<class 'dict'> |
clear , copy , fromkeys , 17 get , 18 items , 19 keys , 20 pop , popitem , setdefault , 21 update , 22 values |
<_io.TextIOWrapper name='file1.txt' mode='r+' encoding='UTF-8'> |
23 close , fileno , flush , 24 mode , name , 25 read , readline , readlines , seek , 26 write , writelines |
https://docs.python.org/3/glossary.html#term-argument
https://docs.python.org/3/glossary.html#term-parameter
What is the difference between arguments and parameters?
Parameters are defined by the names that appear in a function definition, whereas arguments are the values actually passed to a function when calling it. Parameters define what types of arguments a function can accept. For example, given the
function definition:
def func (foo, bar=None, **kwargs)
pass
foo
, bar
and wargs
are parameters of func
However, when calling func for example func(42, bar=314, extra=somevar)
the values 42 314, and somevar are arguments.
argument
A value passed to a function (or method when calling the function. There are two kinds of arguments:
keyword argument: an argument preceded by an identifier ( e.g. name in a function call). For example, 3 and 5 are both keyword arguments in the following calls to
complex(real=3, imag=5)
positional argument: an argument that is not a keyword argument. Positional arguments in the following calls:
complex (3, 5)
Arguments are assigned to the named local variables (aka parameters) in a function body.
parameters
A named entity in a function (or method) definition that specifies an argument (or in some cases, arguments that the function can accept. There are five kinds of parameters.
Main benefit: Code is shorter and sometimes more clearer.
Code Snippet
Lines 1-6
is equivalent to Lines 11-12
and equivalent to Line 17
.
Output of Code Snippet
"…it reminded me that seemingly trivial questions may have rather deep answers.” http://bit.ly/deepAnswer
Credit: https://twitter.com/dbader_org/status/874653012374859776
Fun fact—Python str
objects are recursive data structures: Each character in a string is a str
of length 1 itself.
I have always wondered how the in-place swap
worked using the XOR operation. The following table went a long way in helping clear up the magic in my head.
arg 1 | arg 2 | Result |
---|---|---|
A | B | C |
B | C | A |
A | C | B |
Therefore,
a = a ^ b # c value in a
b = a ^ b # b now contains a (since c ^ b -> a)
a = a ^ b # a now contains b (since c ^ a -> b)
http://www.brunton-spall.co.uk/post/2010/09/07/interview-questions-xor-trick-and-why-you-should-j/
tl;dr package: A Python module which can contain submodules or recursively, subpackages. Technically, a package is a Python module with an path attribute.
tl; dr2 Packages are modules too. They are just packaged up differently; they are formed by the combination of a directory plus
__init__.py
file. They are modules that can contain other modules.
Any Python file is a module, its name being the file’s base name without the .py
extension. A package is a collection of Python modules: while a module is a single Python file, a package is a directory of Python modules containing an additional __init__.py
file, to distinguish a package from a directory that just happens to contain a bunch of Python scripts. Packages can be nested to any depth, provided that the corresponding directories contain their own __init__.py
file.
The distinction between module and package seems to hold just at the file system level. When you import a module or a package, the corresponding object created by Python is always of type module
. Note, however, when you import a package, only variables/functions/classes in the __init__.py
file of that package are directly visible, not sub-packages or modules. As an example, consider the xml
package in the Python standard library: its xml
directory contains an __init__.py
file and four sub-directories; the sub-directory etree
contains an __init__.py
file and, among others, an ElementTree.py
file. See what happens when you try to interactively import package/modules:
>>> import xml
>>> type(xml)
<type 'module'>
>>> xml.etree.ElementTree
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'etree'
>>> import xml.etree
>>> type(xml.etree)
<type 'module'>
>>> xml.etree.ElementTree
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'ElementTree'
>>> import xml.etree.ElementTree
>>> type(xml.etree.ElementTree)
<type 'module'>
>>> xml.etree.ElementTree.parse
<function parse at 0x00B135B0>
You need to maintain a list in sorted order without having to call sort
each time an item is added to the list. How will you do this?
http://www.pixelmonkey.org/2015/06/06/pybooks
https://www.safaribooksonline.com/library/view/python-in-a/9781491913833/
https://docs.python-guide.org/intro/learning/#beginner
The best programming practice book!
ByKevin Lon April 17, 2017
Format: Paperback
tl;dr When it comes to programming practice, Elements of Programming Interviews is the cream of the crop. If you are only going to buy one practice book, I would recommend this one above all the others. I have nothing but good things to say about the book, and can confidently say that no other product that offers as much depth as EoPI does.
The first thing you will notice about EoPI is that the level of detail is astounding; I was blown away by the sheer amount of effort that the authors put into it. The problem analysis is unparalleled, and goes far beyond basic algorithm/data structures knowledge. The solutions are easy to follow and explained very thoroughly. For example, if a problem has multiple solutions, the authors will walk you through each one and guide you towards the optimal solution. In addition to being a goldmine of commonly-asked problems, the book also offers many original problems that you wouldn’t be able to find anywhere else; it is by far the most comprehensive practice resource out there. In terms of organization the book is extremely well structured, and even provides study plans for the reader to help with problem selection. Some of the problems in the book are much more difficult than what you would find in an actual interview. If you are able to comfortably solve the problems in this book, you should certainly have no problem with the real thing.
Before using this book I tried various other resources, particularly Cracking the Coding Interview and LeetCode. The former offered no depth whatsoever: mostly simple and overused problems (like what you would get in a technical phone screen). While the latter provided no shortage of challenging problems, I found it sometimes frustrating to use because of its unclear problem statements and its reliance on an auto-grader to compensate for lack of published solutions and guidance.
I have long been a fan of the series and I am delighted to see that a Python version has been released. I give Elements of Programming Interviews 5-stars because I think it is an essential practice resource. Honestly, it was a lot of fun to work through the book; it was much more pleasant than the usual practice problem grind. Even if you are not practicing for interviews at the time, I highly recommend checking it out. It is a great way to develop your problem solving ability and build confidence for future interviews.
https://www.amazon.com/dp/1537713949/ref=cm_wl_huc_continue
Python expertise awaits. Whether you are a pair of hackers building a prototype for a new startup; a 20-person team that is doing large-scale engineering with Python; or a thousand-person engineering department that is switching from Java/C++, your team will benefit greatly from copies of each of these!
You’ll all be certified Pythonistas in no time. Welcome to the community, and Happy Hacking!
https://doughellmann.com/blog/the-python-3-standard-library-by-example/
http://my.safaribooksonline.com/book/programming/python/9780134291154 - book TOC