Lab3003
  • FacultyAlgorithmChallenge
  • README
  • Question Bank
  • Python Documentation
    • BetterMap
    • Board
    • Card
    • Circle
    • Deck
    • README.md
    • Guide For Bookmarklet
    • Hand
    • HashMap
    • Hist
    • Kangaroo
    • LinearMap
    • Markov
    • Point
    • PokerDeck
    • PokerHand
    • Rectangle
    • State
    • Test
    • ThinkPython
    • ThinkPython2
    • Time
    • Think Python
    • thinkpython
  • Files
  • Image Files
  • lab
    • InsertSortTDD
    • countingBits
    • cs3003mergeSortLectureGuideLine
    • index_min
    • insort
    • One-line factorial function in Python
  • Manual for Python Lab
    • COURSE OBJECTIVES
    • 1_timelines
    • FDPNotes
    • PC-2_Python
    • lab1-kgashok.py
    • Lab 10 :Matrix Multiplication
    • Lab 11: Programs that take command line arguments (word count)
    • Lab 11: Programs that take command line arguments
    • Lab 12: Compute the most frequently used words from the text file
    • Lab 12: Find the most frequent words in a text read from a file
    • Lab 12a: File content sorter
    • Lab 2: Find the square root of a number (Newton’s method)
    • Lab 3: Compute power of a number (Exponentiation)
    • Lab 3: Exponentiation (power of a number)
    • lab4-binaraysearch-anvar.py
    • Solution for Binary Search
    • lab4-joelanandraj-binarysearch.py
    • Lab 4: Linear and Binary Search
    • lab4-lin-anvar.py
    • Linear Searcher
    • Lab 5 : find n prime numbers
    • lab6-kgashok.py
    • lab7-kgashok.py
    • lab8-kgashok.py
    • Lab 8: Selection and Insertion sort using Python
    • Merge Sort
    • Quick Sort
    • labSheet
    • pc0
    • sortPythonic
    • Sorting
  • misc
    • Bookmarklets
    • Guide For Bookmarklet
    • pythonResources
    • FDP for Python
    • Agenda for Workshop
      • Agenda
  • notes
    • Problem Set
    • InsertSortTDD
    • MergeSort
    • cs3003-unit1-notes
    • cs3003-unit3
    • cs3003-unit4-examples
    • Unit 4 Lists, Tuples and Dictionaries
    • cs3003insertsortLectureGuide
    • cs3003mergeSortLectureGuideLine
    • Designing and Delivering Effective Lectures
    • histogram.py
    • selectSortLectureGuide
  • Sandbox to try ThinkPy2 code
    • Code from ThinkPython Github repository
  • Important Topics
    • 3003-syllabus
    • GE8161 PROBLEM SOLVING AND PYTHON PROGRAMMING LABORATORY L T P C
    • Unit II Version 2
    • Unit IV material
    • UNIT III CONTROL FLOW, FUNCTIONS
    • Unit 1 Algorithm Problem Solving
    • Unit_V_Notes
    • UpdatedSyllabus
    • glossary
    • glossaryGeneration.py
    • importantTopics-kgashok
    • memCSV
    • Tower of Hanoi
    • Notes for Unit 2 - Illustrative programs
    • unit5-updated_notes
    • unit_1_notes
    • Unit 3 Control Flow Version 1
    • unit 3
      • UNIT III CONTROL FLOW, FUNCTIONS
    • unit_i_img
Powered by GitBook
On this page
  • Useful links to explore
  • To read and incorporate
  • Tutorials
  • Misc
  • Important Concepts
  • 0.0 Iterables
  • 0.1 Types and their attributes (aka methods, Unit 3)
  • 1. Differentiate between parameters and arguments (Unit 3)
  • 2. Explain Immutability with reference to the various data types in Python. (Unit 3)
  • 3. What is list comprehension and what is the main benefit? Describe with an example. (Unit 4)
  • 4. Slicing as an Object
  • 5. If Python is interpreted, what are .pyc files?
  • 6. A String is a recursive data structure. True or False?
  • 7. The XOR trick, grokked, finally!
  • 8. Packages and Modules
  • 9. How to maintain a sorted list?
  • Misc
  • Important Links
  • The best 3 books
  • Learn by Example
  • List Methods and Operations
  1. Important Topics

importantTopics-kgashok

PreviousglossaryGeneration.pyNextmemCSV

Last updated 3 years ago

Want a ToC? View at

Useful links to explore

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.

To read and incorporate

  • 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

  • http://docs.python-guide.org/en/latest/intro/learning/

  • https://danieltakeshi.github.io/2013/07/05/ten-things-python-programmers-should-know/

  • https://www.quora.com/What-are-the-most-important-topics-to-learn-in-Python/answer/Janarthanan-S-1?srid=ul6v

  • https://stackoverflow.com/questions/2439638/in-what-order-should-the-python-concepts-be-explained-to-absolute-beginners

Tutorials

  • Top links

    • http://j.mp/pythonREPLcourse - repl.it based

    • Useful CheatSheet - https://gto76.github.io/python-cheatsheet/

    • University of Waterloo Tutorial https://cscircles.cemc.uwaterloo.ca/

    • https://www.codeforlife.education/rapidrouter - better transfer or complement to Blockly

      • - Rapid Router - what next? http://j.mp/rapidNext
    • http://www.learnpython.org/

  • https://www.quora.com/How-should-I-start-learning-Python-1?redirected_qid=907

  • http://j.mp/pythonKoanVideo

    • https://github.com/gregmalcolm/python_koans - 289 koans to enlightenment!

  • 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.

    • https://medium.com/@sebastienphl/a-practical-guide-to-learning-the-basics-of-web-programming-79961f3f3baa

      • http://pythonpracticeprojects.com/

      • http://javascriptissexy.com/how-to-learn-javascript-properly/

  • https://medium.com/@sebastienphl/a-practical-guide-to-learning-the-basics-of-web-programming-79961f3f3baa

Misc

  • Beginner ML projects - https://elitedatascience.com/machine-learning-projects-for-beginners

  • See some beautiful Python poems - https://www.reddit.com/r/programming/comments/26dyh/ask_reddit_whats_the_most_beautiful_piece_of/c26ny9/

  • https://www.reddit.com/r/programming/wiki/faq

  • https://www.quora.com/How-does-Quincy-Larson-suggest-I-learn-to-code/answer/Quincy-Larson

    • https://www.quora.com/What-is-a-step-by-step-procedure-to-become-a-GitHub-open-source-developer-for-a-complete-newbie-What-are-the-prerequisite-courses-I-should-take-and-how-should-I-choose-the-best-project-Also-please-suggest-some-projects-in-C++-Java/answer/Quincy-Larson

    • https://github.com/search?l=Python&q=label%3Afirst-timers-only&state=open&type=Issues

Table of Contents

Important Concepts

0.0 Iterables

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 variable

  • adict.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]]

0.1 Types and their attributes (aka methods, Unit 3)

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

1. Differentiate between parameters and arguments (Unit 3)

  • http://j.mp/argsVsParams - the official Python guide does not do justice. It is best to read this article here - http://stupidpythonideas.blogspot.in/2013/08/arguments-and-parameters.html

Argument Definition

Parameter Definition

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.

2. Explain Immutability with reference to the various data types in Python. (Unit 3)

Everything is an Object

What is ID?

What is value?

Immutable and Mutable

3. What is list comprehension and what is the main benefit? Describe with an example. (Unit 4)

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

4. Slicing as an Object

j.mp/sliceDoc

5. If Python is interpreted, what are .pyc files?

"...it reminded me that seemingly trivial questions may have rather deep answers.” http://bit.ly/deepAnswer

6. A String is a recursive data structure. True or False?

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.

7. The XOR trick, grokked, finally!

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)

Credits

http://www.brunton-spall.co.uk/post/2010/09/07/interview-questions-xor-trick-and-why-you-should-j/

8. Packages and Modules

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.

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>

9. How to maintain a sorted list?

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?

Misc

Important Links

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

The best 3 books

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!

  • Python Essential Reference, 4e (Beazley)

  • Fluent Python, 1e (Ramalho)

  • Python Cookbook, 3e (Beazley, Jones)

  • Bonus: Python Cookbook, 2e (Martelli, Ascher)

You’ll all be certified Pythonistas in no time. Welcome to the community, and Happy Hacking!

Learn by Example

What standard libraries to learn in Python?

List Methods and Operations

What's new in Python 3? Read

faqArg

https://docs.python.org/3/glossary.html#term-argument

https://docs.python.org/3/glossary.html#term-parameter

object
id
value
immutableP
mutableP
mCode
mOutput
immutableTable
list_comprehension
listCode
listOut
slice
stringRecursive

Any Python file is a , its name being the file's base name without the .py extension. A 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.

- book TOC

See

this
pdf version
module
package
https://doughellmann.com/blog/the-python-3-standard-library-by-example/
https://doughellmann.com/blog/the-python-3-standard-library-by-example/the-python-3-standard-library-by-example-table-of-contents/
http://my.safaribooksonline.com/book/programming/python/9780134291154
http://j.mp/listThis
Important Concepts
0. Types and their attributes (aka methods, Unit 3)
1. Differentiate between parameters and arguments (Unit 3)
Argument Definition
Parameter Definition
2. Explain Immutability with reference to the various data types in Python. (Unit 3)
Everything is an Object
What is ID?
What is value?
Immutable and Mutable
3. What is list comprehension and what is the main benefit? Describe with an example. (Unit 4)
4. Slicing as an Object
5. If Python is interpreted, what are .pyc files?
6. A String is a recursive data structure. True or False?
7. The XOR trick, grokked, finally!
Credits
8. Packages and Modules
9. How to maintain a sorted list?
Misc
Important Links
The best 3 books
Learn by Example
What standard libraries to learn in Python?
http://j.mp/importantPy
aditi
argument
parameter