Though there can be many but as i am very new to python so which modules or classes within standard libraries i should know when programming in python, especially when i am practicing programming challenges from a C++ book? Libraries which can make my life easier? Since there can be no single correct answer, i am making this question a wiki.
The standard library, especially the built-in functions. They seem trivial but can yield impressive results!
It really pays to know the basics of a default python installation. If you doubt that just follow the Stack Overflow python questions. Some answers are just amazing :)
The standard libraries, i.e. the ones considered more or less part of Python. Start with those, there is plenty to learn before starting on 3rd party stuff.
Things like:
The re
module is a must. itertools
also often comes handy.
Generally speaking: Take a deep look at Standard library. Then you might think about wxPython for GUI, numPy for computations, Django for web and Amara for XML, and... there's plenty of Python libs and modules out there. Just suit your needs.
Check out the excellent Python Module of the Week blog series.
Since you ask about libraries, not specific modules in them, the standard library that comes with Python is the first and most fundamental answer; the programming challenges from a C++ book are unlikely to require anything beyond that (such as GUI toolkits) -- perhaps numpy/scipy if the book is heavily slanted to scientific programming.
Actually, to work problems from a C++ book using Python, you mainly just need to master Python's built-in types, especially the data structures tuple
, list
, set
, and dict
; and the built-in functions, like max
, min
, sorted
, and reversed
.
These builtins have a lot of features that aren't obvious at first, such as the in
keyword, the optional key=
argument to list.sort
, list slicing, sequence multiplication, the dict(list_of_pairs)
constructor, del
, tuple unpacking, and so on. It's fun to learn these, and they make Python a real joy to use.
Also see collections.defaultdict
. If you need file I/O, read about open
and file objects.
Seems too fundamental, but when getting started with python (lets face it, I'm still learning it) I missed some functions in the math module that would have been helpful. I ended up writing my own versions which worked but I could have saved time...