pygtrie Release Jul 03, 2017

Size: px
Start display at page:

Download "pygtrie Release Jul 03, 2017"

Transcription

1 pygtrie Release Jul 03, 2017

2

3 Contents 1 Features 3 2 Installation 5 3 Upgrading from 0.9.x 7 4 Trie classes 9 5 PrefixSet class 19 6 Version History 21 Python Module Index 23 i

4 ii

5 Implementation of a trie data structure. Trie data structure, also known as radix or prefix tree, is a tree associating keys to values where all the descendants of a node have a common prefix (associated with that node). The trie module contains pygtrie.trie, pygtrie.chartrie and pygtrie.stringtrie classes each implementing a mutable mapping interface, i.e. dict interface. As such, in most circumstances, pygtrie.trie could be used as a drop-in replacement for a dict, but the prefix nature of the data structure is trie s real strength. The module also contains pygtrie.prefixset class which uses a trie to store a set of prefixes such that a key is contained in the set if it or its prefix is stored in the set. Contents 1

6 2 Contents

7 CHAPTER 1 Features A full mutable mapping implementation. Supports iterating over as well as deleting a subtrie. Supports prefix checking as well as shortest and longest prefix look-up. Extensible for any kind of user-defined keys. A PrefixSet supports all keys starting with given prefix logic. Can store any value including None. For some simple examples see example.py file. 3

8 4 Chapter 1. Features

9 CHAPTER 2 Installation To install pygtrie, run: pip install pygtrie Or download the sources and save pygtrie.py file with your project. 5

10 6 Chapter 2. Installation

11 CHAPTER 3 Upgrading from 0.9.x The 1.0 release introduced backwards incompatibility in naming. The module has been renamed from trie to pygtrie. Fortunately, updating scripts using pygtrie should boil down to replacing: from pytrie import trie with: import pygtrie as trie 7

12 8 Chapter 3. Upgrading from 0.9.x

13 CHAPTER 4 Trie classes class Trie(*args, **kwargs) A trie implementation with dict interface plus some extensions. Keys used with the pygtrie.trie must be iterable, yielding hashable objects. In other words, for a given key, dict.fromkeys(key) must be valid. In particular, strings work fine as trie keys, however when getting keys back from iterkeys() method for example, instead of strings, tuples of characters are produced. For that reason, pygtrie.chartrie or pygtrie. StringTrie may be preferred when using pygtrie.trie with string keys. delitem (key_or_slice) Deletes value associated with given key or raises KeyError. If argument is a key, value associated with it is deleted. If the key is also a prefix, its descendents are not affected. On the other hand, if the argument is a slice (in which case it must have only start set), the whole subtrie is removed. For example: >>> import pygtrie >>> t = pygtrie.stringtrie() >>> t['foo'] = 'Foo' >>> t['foo/bar'] = 'Bar' >>> t['foo/bar/baz'] = 'Baz' >>> del t['foo/bar'] >>> t.keys() ['foo', 'foo/bar/baz'] >>> del t['foo':] >>> t.keys() [] Parameters key_or_slice A key to look for or a slice. If key is a slice, the whole subtrie will be removed. Raises ShortKeyError If the key has no value associated with it but is a prefix of some key with a value. This is not thrown is key_or_slice is a slice in such cases, the whole subtrie 9

14 is removed. Note that ShortKeyError is subclass of KeyError. KeyError If key has no value associated with it nor is a prefix of an existing key. TypeError If key is a slice whose stop or step are not None. getitem (key_or_slice) Returns value associated with given key or raises KeyError. When argument is a single key, value for that key is returned (or KeyError exception is thrown if the node does not exist or has no value associated with it). When argument is a slice, it must be one with only start set in which case the access is identical to Trie. itervalues invocation with prefix argument. Example >>> import pygtrie >>> t = pygtrie.stringtrie() >>> t['foo/bar'] = 'Bar' >>> t['foo/baz'] = 'Baz' >>> t['qux'] = 'Qux' >>> t['foo/bar'] 'Bar' >>> list(t['foo':]) ['Baz', 'Bar'] >>> t['foo'] Traceback (most recent call last):... pygtrie.shortkeyerror: 'foo' Parameters key_or_slice A key or a slice to look for. Returns If a single key is passed, a value associated with given key. If a slice is passed, a generator of values in specified subtrie. Raises ShortKeyError If the key has no value associated with it but is a prefix of some key with a value. Note that ShortKeyError is subclass of KeyError. KeyError If key has no value associated with it nor is a prefix of an existing key. TypeError If key_or_slice is a slice but it s stop or step are not None. init (*args, **kwargs) Initialises the trie. Arguments are interpreted the same way Trie.update interprets them. len () Returns number of values in a trie. Note that this method is expensive as it iterates over the whole trie. setitem (key_or_slice, value) Sets value associated with given key. If key_or_slice is a key, simply associate it with given value. If it is a slice (which must have start set only), it in addition clears any subtrie that might have been attached to particular key. For example: 10 Chapter 4. Trie classes

15 >>> import pygtrie >>> t = pygtrie.stringtrie() >>> t['foo/bar'] = 'Bar' >>> t['foo/baz'] = 'Baz' >>> t.keys() ['foo/baz', 'foo/bar'] >>> t['foo':] = 'Foo' >>> t.keys() ['foo'] Parameters key_or_slice A key to look for or a slice. If it is a slice, the whole subtrie (if present) will be replaced by a single node with given value set. value Value to set. Raises TypeError If key is a slice whose stop or step are not None. clear() Removes all the values from the trie. copy() Returns a shallow copy of the trie. enable_sorting(enable=true) Enables sorting of child nodes when iterating and traversing. Normally, child nodes are not sorted when iterating or traversing over the trie (just like dict elements are not sorted). This method allows sorting to be enabled (which was the behaviour prior to pygtrie 2.0 release). For Trie class, enabling sorting of children is identical to simply sorting the list of items since Trie returns keys as tuples. However, for other implementations such as StringTrie the two may behove subtly different. For example, sorting items might produce: root/foo-bar root/foo/baz even though foo comes before foo-bar. Parameters enable Whether to enable sorting of child nodes. classmethod fromkeys(keys, value=none) Creates a new trie with given keys set. This is roughly equivalent to calling the constructor with a (key, value) for key in keys generator. Parameters keys An iterable of keys that should be set in the new trie. value Value to associate with given keys. Returns A new trie where each key from keys has been set to the given value. has_key(key) Indicates whether given key has value associated with it. See Trie.has_node for more detailed documentation. 11

16 has_node(key) Returns whether given node is in the trie. Return value is a bitwise or of HAS_VALUE and HAS_SUBTRIE constants indicating node has a value associated with it and that it is a prefix of another existing key respectively. Both of those are independent of each other and all of the four combinations are possible. For example: >>> import pygtrie >>> t = pygtrie.stringtrie() >>> t['foo/bar'] = 'Bar' >>> t['foo/bar/baz'] = 'Baz' >>> t.has_node('qux') == 0 True >>> t.has_node('foo/bar/baz') == pygtrie.trie.has_value True >>> t.has_node('foo') == pygtrie.trie.has_subtrie True >>> t.has_node('foo/bar') == (pygtrie.trie.has_value... pygtrie.trie.has_subtrie) True There are two higher level methods built on top of this one which give easier interface for the information. Trie.has_key and returns whether node has a value associated with it and Trie.has_subtrie checks whether node is a prefix. Continuing previous example: >>> t.has_key('qux'), t.has_subtrie('qux') False, False >>> t.has_key('foo/bar/baz'), t.has_subtrie('foo/bar/baz') True, False >>> t.has_key('foo'), t.has_subtrie('foo') False, True >>> t.has_key('foo/bar'), t.has_subtrie('foo/bar') True, True Parameters key A key to look for. Returns Non-zero if node exists and if it does a bit-field denoting whether it has a value associated with it and whether it has a subtrie. has_subtrie(key) Returns whether given key is a prefix of another key in the trie. See Trie.has_node for more detailed documentation. items(prefix=<object object>, shallow=false) Returns a list of (key, value) pairs in given subtrie. This is equivalent to constructing a list from generator returned by Trie.iteritems which see for more detailed documentation. iteritems(prefix=<object object>, shallow=false) Yields all nodes with associated values with given prefix. Only nodes with values are output. For example: >>> import pygtrie >>> t = pygtrie.stringtrie() >>> t['foo'] = 'Foo' >>> t['foo/bar/baz'] = 'Baz' 12 Chapter 4. Trie classes

17 >>> t['qux'] = 'Qux' >>> t.items() [('qux', 'Qux'), ('foo', 'Foo'), ('foo/bar/baz', 'Baz')] Items are generated in topological order but the order of siblings is unspecified by default. In other words, in the above example, the ('qux', 'Qux') pair might have been at the end of the list. At an expense of efficiency, this can be changed via Trie.enable_sorting. With prefix argument, only items with specified prefix are generated (i.e. only given subtrie is traversed) as demonstrated by: >>> t.items(prefix='foo/bar') [('foo/bar/baz', 'Baz')] With shallow argument, if a node has value associated with it, it s children are not traversed even if they exist which can be seen in: >>> t.items(shallow=true) [('qux', 'Qux'), ('foo', 'Foo')] Parameters prefix Prefix to limit iteration to. shallow Perform a shallow traversal, i.e. do not yield items if their prefix has been yielded. Yields (key, value) tuples. Raises KeyError If prefix does not match any node. iterkeys(prefix=<object object>, shallow=false) Yields all keys having associated values with given prefix. This is equivalent to taking first element of tuples generated by Trie.iteritems which see for more detailed documentation. Parameters prefix Prefix to limit iteration to. shallow Perform a shallow traversal, i.e. do not yield keys if their prefix has been yielded. Yields All the keys (with given prefix) with associated values in the trie. Raises KeyError If prefix does not match any node. itervalues(prefix=<object object>, shallow=false) Yields all values associated with keys with given prefix. This is equivalent to taking second element of tuples generated by Trie.iteritems which see for more detailed documentation. Parameters prefix Prefix to limit iteration to. shallow Perform a shallow traversal, i.e. do not yield values if their prefix has been yielded. Yields All the values associated with keys (with given prefix) in the trie. 13

18 Raises KeyError If prefix does not match any node. keys(prefix=<object object>, shallow=false) Returns a list of all the keys, with given prefix, in the trie. This is equivalent to constructing a list from generator returned by Trie.iterkeys which see for more detailed documentation. longest_prefix(key) Finds the longest prefix of a key with a value. This is equivalent to taking the last object yielded by Trie.prefixes with a default of (None, None) if said method yields no items. As an added bonus, the pair in that case will be a falsy value (as opposed to regular two-element tuple of None values). Example >>> import pygtrie >>> t = pygtrie.stringtrie() >>> t['foo'] = 'Foo' >>> t['foo/bar/baz'] = 'Baz' >>> t.longest_prefix('foo/bar/baz/qux') ('foo/bar/baz', 'Baz') >>> t.longest_prefix('does/not/exist') (None, None) >>> bool(t.longest_prefix('does/not/exist')) False Parameters key Key to look for. Returns (k, value) where k is the longest prefix of key (it may equal key) and value is a value associated with that key. If no node is found, (None, None) is returned. pop(key, default=<object object>) Deletes value associated with given key and returns it. Parameters key A key to look for. default If specified, value that will be returned if given key has no value associated with it. If not specified, method will throw KeyError in such cases. Returns Removed value, if key had value associated with it, or default (if given). Raises ShortKeyError If default has not been specified and the key has no value associated with it but is a prefix of some key with a value. Note that ShortKeyError is subclass of KeyError. KeyError If default has not been specified and key has no value associated with it nor is a prefix of an existing key. popitem() Deletes an arbitrary value from the trie and returns it. There is no guarantee as to which item is deleted and returned. Neither in respect to its lexicographical nor topological order. 14 Chapter 4. Trie classes

19 Returns (key, value) tuple indicating deleted key. Raises KeyError If the trie is empty. prefixes(key) Walks towards the node specified by key and yields all found items. Example >>> import pygtrie >>> t = pygtrie.stringtrie() >>> t['foo'] = 'Foo' >>> t['foo/bar/baz'] = 'Baz' >>> list(t.prefixes('foo/bar/baz/qux')) [('foo', 'Foo'), ('foo/bar/baz', 'Baz')] >>> list(t.prefixes('does/not/exist')) [] Parameters key Key to look for. Yields (k, value) pairs denoting keys with associated values encountered on the way towards the specified key. setdefault(key, value=none) Sets value of a given node if not set already. Also returns it. In contrast to Trie. setitem, this method does not accept slice as a key. shortest_prefix(key) Finds the shortest prefix of a key with a value. This is equivalent to taking the first object yielded by Trie.prefixes with a default of (None, None) if said method yields no items. As an added bonus, the pair in that case will be a falsy value (as opposed to regular two-element tuple of None values). Example >>> import pygtrie >>> t = pygtrie.stringtrie() >>> t['foo'] = 'Foo' >>> t['foo/bar/baz'] = 'Baz' >>> t.shortest_prefix('foo/bar/baz/qux') ('foo', 'Foo') >>> t.shortest_prefix('does/not/exist') (None, None) >>> bool(t.shortest_prefix('does/not/exist')) False Parameters key Key to look for. Returns (k, value) where k is the shortest prefix of key (it may equal key) and value is a value associated with that key. If no node is found, (None, None) is returned. traverse(node_factory, prefix=<object object>) Traverses the tree using node_factory object. 15

20 node_factory is a callable function which accepts (path_conv, path, children, value=...) arguments, where path_conv is a lambda converting path representation to key, path is the path to this node, children is an iterable of children nodes constructed by node_factory, optional value is the value associated with the path. node_factory s children argument is a generator which has a few consequences: To traverse into node s children, the generator must be iterated over. This can by accomplished by a simple children = list(children) statement. Ignoring the argument allows node_factory to stop the traversal from going into the children of the node. In other words, whole subtrie can be removed from traversal if node_factory chooses so. If children is stored as is (i.e. as a generator) when it is iterated over later on it will see state of the trie as it is during the iteration and not when traverse method was called. Trie.traverse has two advantages over Trie.iteritems and similar methods: 1.it allows subtries to be skipped completely when going through the list of nodes based on the property of the parent node; and 2.it represents structure of the trie directly making it easy to convert structure into a different representation. For example, the below snippet prints all files in current directory counting how many HTML files were found but ignores hidden files and directories (i.e. those whose names start with a dot): import os import pygtrie t = pygtrie.stringtrie(separator=os.sep) # Construct a trie with all files in current directory and all # of its sub-directories. Files get set a True value. # Directories are represented implicitly by being prefixes of # files. for root, _, files in os.walk('.'): for name in files: t[os.path.join(root, name)] = True def traverse_callback(path_conv, path, children, is_file=false): if path and path[-1]!= '.' and path[-1][0] == '.': # Ignore hidden directory (but accept root node and '.') return 0 elif is_file: print path_conv(path) return int(path[-1].endswith('.html')) else: # Otherwise, it's a directory. Traverse into children. return sum(int(is_html) for is_html in children) print t.traverse(traverse_callback) As documented, ignoring the children argument causes subtrie to be omitted and not walked into. In the next example, the trie is converted to a tree representation where child nodes include a pointer to their parent. As before, hidden files and directories are ignored: import os import pygtrie t = pygtrie.stringtrie(separator=os.sep) for root, _, files in os.walk('.'): 16 Chapter 4. Trie classes

21 for name in files: t[os.path.join(root, name)] = True class File(object): def init (self, name): self.name = name self.parent = None class Directory(File): def init (self, name, children): super(directory, self). init (name) self._children = children for child in children: child.parent = self def traverse_callback(path_conv, path, children, is_file=false): if not path or path[-1] == '.' or path[-1][0]!= '.': if is_file: return File(path[-1]) children = filter(none, children) return Directory(path[-1] if path else '', children) root = t.traverse(traverse_callback) Note: Unlike iterators, traverse method uses stack recursion which means that using it on deep tries may lead to a RuntimeError exception thrown once Python s maximum recursion depth is reached. Parameters node_factory Makes opaque objects from the keys and values of the trie. prefix Prefix for node to start traversal, by default starts at root. Returns Node object constructed by node_factory corresponding to the root node. update(*args, **kwargs) Updates stored values. Works like dict.update. values(prefix=<object object>, shallow=false) Returns a list of values in given subtrie. This is equivalent to constructing a list from generator returned by Trie.iterivalues which see for more detailed documentation. class CharTrie(*args, **kwargs) A variant of a pygtrie.trie which accepts strings as keys. The only difference between pygtrie.chartrie and pygtrie.trie is that when pygtrie. CharTrie returns keys back to the client (for instance in keys() method is called), those keys are returned as strings. Canonical example where this class can be used is a dictionary of words in a natural language. For example: >>> import pygtrie >>> t = pygtrie.chartrie() >>> t['wombat'] = True >>> t['woman'] = True >>> t['man'] = True >>> t['manhole'] = True >>> t.has_subtrie('wo') True >>> t.has_key('man') 17

22 True >>> t.has_subtrie('man') True >>> t.has_subtrie('manhole') False class StringTrie(*args, **kwargs) pygtrie.trie variant accepting strings with a separator as keys. The trie accepts strings as keys which are split into components using a separator specified during initialisation ( / by default). Canonical example where this class can be used is when keys are paths. For example, it could map from a path to a request handler: import pygtrie def handle_root(): pass def handle_admin(): pass def handle_admin_images(): pass handlers = pygtrie.stringtrie() handlers[''] = handle_root handlers['/admin'] = handle_admin handlers['/admin/images'] = handle_admin_images request_path = '/admin/images/foo' handler = handlers.longest_prefix(request_path) init (*args, **kwargs) Initialises the trie. Except for a separator named argument, all other arguments are interpreted the same way Trie. update interprets them. Parameters *args Passed to super class initialiser. **kwargs Passed to super class initialiser. separator A separator to use when splitting keys into paths used by the trie. / is used if this argument is not specified. This named argument is not specified on the function s prototype because of Python s limitations. 18 Chapter 4. Trie classes

23 CHAPTER 5 PrefixSet class class PrefixSet(iterable=None, factory=<class pygtrie.trie >, **kwargs) A set of prefixes. pygtrie.prefixset works similar to a normal set except it is said to contain a key if the key or it s prefix is stored in the set. For instance, if foo is added to the set, the set contains foo as well as foobar. The set supports addition of elements but does not support removal of elements. This is because there s no obvious consistent and intuitive behaviour for element deletion. contains (key) Checks whether set contains key or its prefix. init (iterable=none, factory=<class pygtrie.trie >, **kwargs) Initialises the prefix set. Parameters iterable A sequence of keys to add to the set. factory A function used to create a trie used by the pygtrie.prefixset. kwargs Additional keyword arguments passed to the factory function. iter () Return iterator over all prefixes in the set. See PrefixSet.iter method for more info. len () Returns number of keys stored in the set. Since a key does not have to be explicitly added to the set to be an element of the set, this method does not count over all possible keys that the set contains (since that would be infinity), but only over the shortest set of prefixes of all the keys the set contains. For example, if foo has been added to the set, the set contains also foobar, but this method will not count foobar. 19

24 add(key) Adds given key to the set. If the set already contains prefix of the key being added, this operation has no effect. If the key being added is a prefix of some existing keys in the set, those keys are deleted and replaced by a single entry for the key being added. For example, if the set contains key foo adding a key foobar does not change anything. On the other hand, if the set contains keys foobar and foobaz, adding a key foo will replace those two keys with a single key foo. This makes a difference when iterating over the keys or counting number of keys. Counter intuitively, adding of a key can decrease size of the set. Parameters key Key to add. clear() Removes all keys from the set. copy() Returns a copy of the prefix set. iter(prefix=<object object>) Iterates over all keys in the set optionally starting with a prefix. Since a key does not have to be explicitly added to the set to be an element of the set, this method does not iterate over all possible keys that the set contains, but only over the shortest set of prefixes of all the keys the set contains. For example, if foo has been added to the set, the set contains also foobar, but this method will not iterate over foobar. If prefix argument is given, method will iterate over keys with given prefix only. The keys yielded from the function if prefix is given does not have to be a subset (in mathematical sense) of the keys yielded when there is not prefix. This happens, if the set contains a prefix of the given prefix. For example, if only foo has been added to the set, iter method called with no arguments will yield foo only. However, when called with foobar argument, it will yield foobar only. 20 Chapter 5. PrefixSet class

25 CHAPTER 6 Version History 2.2: 2017/06/03 Fixes to setup.py breaking on Windows which prevents installation among other things. 2.1: 2017/03/23 The library is now Python 3 compatible. Value returend by shortest_prefix and longest_prefix evaluates to false if no prefix was found. This is in addition to it being a pair of Nones of course. 2.0: 2016/07/06 Sorting of child nodes is disabled by default for better performance. enable_sorting method can be used to bring back old behaviour. Tries of arbitrary depth can be pickled without reaching Python s recursion limits. (N.B. The pickle format is incompatible with one from 1.2 release). _Node s getstate and setstate method can be used to implement other serialisation methods such as JSON. 1.2: 2016/06/21 [pulled back from PyPi] Tries can now be pickled. Iterating no longer uses recursion so tries of arbitrary depth can be iterated over. The traverse method, however, still uses recursion thus cannot be used on big structures. 1.1: 2016/01/18 Fixed PyPi installation issues; all should work now. 1.0: 2015/12/16 The module has been renamed from trie to pygtrie. This could break current users but see documentation for how to quickly upgrade your scripts. Added traverse method which goes through the nodes of the trie preserving structure of the tree. This is a depth-first traversal which can be used to search for elements or translate a trie into a different tree structure. Minor documentation fixes. 21

26 0.9.3: 2015/05/28 Minor documentation fixes : 2015/05/28 Added Sphinx configuration and updated docstrings to work better with Sphinx : 2014/02/03 New name. 0.9: 2014/02/03 Initial release. 22 Chapter 6. Version History

27 Python Module Index p pygtrie, 3 23

28 24 Python Module Index

29 Index Symbols contains () (PrefixSet method), 19 delitem () (Trie method), 9 getitem () (Trie method), 10 init () (PrefixSet method), 19 init () (StringTrie method), 18 init () (Trie method), 10 iter () (PrefixSet method), 19 len () (PrefixSet method), 19 len () (Trie method), 10 setitem () (Trie method), 10 A add() (PrefixSet method), 19 C CharTrie (class in pygtrie), 17 clear() (PrefixSet method), 20 clear() (Trie method), 11 copy() (PrefixSet method), 20 copy() (Trie method), 11 E enable_sorting() (Trie method), 11 F fromkeys() (pygtrie.trie class method), 11 H has_key() (Trie method), 11 has_node() (Trie method), 11 has_subtrie() (Trie method), 12 I items() (Trie method), 12 iter() (PrefixSet method), 20 iteritems() (Trie method), 12 iterkeys() (Trie method), 13 itervalues() (Trie method), 13 K keys() (Trie method), 14 L longest_prefix() (Trie method), 14 P pop() (Trie method), 14 popitem() (Trie method), 14 prefixes() (Trie method), 15 PrefixSet (class in pygtrie), 19 pygtrie (module), 1 S setdefault() (Trie method), 15 shortest_prefix() (Trie method), 15 StringTrie (class in pygtrie), 18 T traverse() (Trie method), 15 Trie (class in pygtrie), 9 U update() (Trie method), 17 V values() (Trie method), 17 25

PyTrie Documentation. Release 0.3. George Sakkis

PyTrie Documentation. Release 0.3. George Sakkis PyTrie Documentation Release 0.3 George Sakkis Jun 05, 2017 Contents 1 Usage 3 2 Reference documentation 5 2.1 Classes.................................................. 5 2.2 Trie methods...............................................

More information

CS Programming Languages: Python

CS Programming Languages: Python CS 3101-1 - Programming Languages: Python Lecture 5: Exceptions / Daniel Bauer (bauer@cs.columbia.edu) October 08 2014 Daniel Bauer CS3101-1 Python - 05 - Exceptions / 1/35 Contents Exceptions Daniel Bauer

More information

Friday, 11 April 14. Advanced methods for creating decorators Graham Dumpleton PyCon US - April 2014

Friday, 11 April 14. Advanced methods for creating decorators Graham Dumpleton PyCon US - April 2014 Advanced methods for creating decorators Graham Dumpleton PyCon US - April 2014 Intermission Rant about the history of this talk and why this topic matters. Python decorator syntax @function_wrapper def

More information

Python review. 1 Python basics. References. CS 234 Naomi Nishimura

Python review. 1 Python basics. References. CS 234 Naomi Nishimura Python review CS 234 Naomi Nishimura The sections below indicate Python material, the degree to which it will be used in the course, and various resources you can use to review the material. You are not

More information

GE PROBLEM SOVING AND PYTHON PROGRAMMING. Question Bank UNIT 1 - ALGORITHMIC PROBLEM SOLVING

GE PROBLEM SOVING AND PYTHON PROGRAMMING. Question Bank UNIT 1 - ALGORITHMIC PROBLEM SOLVING GE8151 - PROBLEM SOVING AND PYTHON PROGRAMMING Question Bank UNIT 1 - ALGORITHMIC PROBLEM SOLVING 1) Define Computer 2) Define algorithm 3) What are the two phases in algorithmic problem solving? 4) Why

More information

Week - 03 Lecture - 18 Recursion. For the last lecture of this week, we will look at recursive functions. (Refer Slide Time: 00:05)

Week - 03 Lecture - 18 Recursion. For the last lecture of this week, we will look at recursive functions. (Refer Slide Time: 00:05) Programming, Data Structures and Algorithms in Python Prof. Madhavan Mukund Department of Computer Science and Engineering Indian Institute of Technology, Madras Week - 03 Lecture - 18 Recursion For the

More information

Exceptions & a Taste of Declarative Programming in SQL

Exceptions & a Taste of Declarative Programming in SQL Exceptions & a Taste of Declarative Programming in SQL David E. Culler CS8 Computational Structures in Data Science http://inst.eecs.berkeley.edu/~cs88 Lecture 12 April 18, 2016 Computational Concepts

More information

CS61A Notes Week 13: Interpreters

CS61A Notes Week 13: Interpreters CS61A Notes Week 13: Interpreters Read-Eval Loop Unlike Python, the result of evaluating an expression is not automatically printed. Instead, Logo complains if the value of any top-level expression is

More information

Dictionaries. Looking up English words in the dictionary. Python sequences and collections. Properties of sequences and collections

Dictionaries. Looking up English words in the dictionary. Python sequences and collections. Properties of sequences and collections Looking up English words in the dictionary Comparing sequences to collections. Sequence : a group of things that come one after the other Collection : a group of (interesting) things brought together for

More information

COMP519 Web Programming Lecture 20: Python (Part 4) Handouts

COMP519 Web Programming Lecture 20: Python (Part 4) Handouts COMP519 Web Programming Lecture 20: Python (Part 4) Handouts Ullrich Hustadt Department of Computer Science School of Electrical Engineering, Electronics, and Computer Science University of Liverpool Contents

More information

IHIH Documentation. Release Romain Dartigues

IHIH Documentation. Release Romain Dartigues IHIH Documentation Release 0.1.1 Romain Dartigues December 11, 2016 Contents 1 Why? 3 2 Table of contents 5 2.1 Source documentation.......................................... 5 2.2 Examples.................................................

More information

Babu Madhav Institute of Information Technology, UTU 2015

Babu Madhav Institute of Information Technology, UTU 2015 Five years Integrated M.Sc.(IT)(Semester 5) Question Bank 060010502:Programming in Python Unit-1:Introduction To Python Q-1 Answer the following Questions in short. 1. Which operator is used for slicing?

More information

Structure and Interpretation of Computer Programs

Structure and Interpretation of Computer Programs CS 6A Spring 203 Structure and Interpretation of Computer Programs Final Solutions INSTRUCTIONS You have 3 hours to complete the exam. The exam is closed book, closed notes, closed computer, closed calculator,

More information

Lecture #15: Generic Functions and Expressivity. Last modified: Wed Mar 1 15:51: CS61A: Lecture #16 1

Lecture #15: Generic Functions and Expressivity. Last modified: Wed Mar 1 15:51: CS61A: Lecture #16 1 Lecture #15: Generic Functions and Expressivity Last modified: Wed Mar 1 15:51:48 2017 CS61A: Lecture #16 1 Consider the function find: Generic Programming def find(l, x, k): """Return the index in L of

More information

rumps Documentation Release Jared Suttles

rumps Documentation Release Jared Suttles rumps Documentation Release 0.2.0 Jared Suttles Nov 14, 2017 Contents 1 Examples 3 1.1 Simple subclass structure........................................ 3 1.2 Decorating any functions.........................................

More information

The WSGI Reference Library

The WSGI Reference Library The WSGI Reference Library Release 0.2 Phillip J. Eby October 4, 2010 Email: pje@telecommunity.com Abstract The Web Server Gateway Interface (WSGI) is a standard interface between web server software and

More information

Data Structures I: Linked Lists

Data Structures I: Linked Lists Lab 4 Data Structures I: Linked Lists Lab Objective: Analyzing and manipulating data are essential skills in scientific computing. Storing, retrieving, and rearranging data take time. As a dataset grows,

More information

MUTABLE LISTS AND DICTIONARIES 4

MUTABLE LISTS AND DICTIONARIES 4 MUTABLE LISTS AND DICTIONARIES 4 COMPUTER SCIENCE 61A Sept. 24, 2012 1 Lists Lists are similar to tuples: the order of the data matters, their indices start at 0. The big difference is that lists are mutable

More information

CSE : Python Programming. Decorators. Announcements. The decorator pattern. The decorator pattern. The decorator pattern

CSE : Python Programming. Decorators. Announcements. The decorator pattern. The decorator pattern. The decorator pattern CSE 399-004: Python Programming Lecture 12: Decorators April 9, 200 http://www.seas.upenn.edu/~cse39904/ Announcements Projects (code and documentation) are due: April 20, 200 at pm There will be informal

More information

Trees : Part 1. Section 4.1. Theory and Terminology. A Tree? A Tree? Theory and Terminology. Theory and Terminology

Trees : Part 1. Section 4.1. Theory and Terminology. A Tree? A Tree? Theory and Terminology. Theory and Terminology Trees : Part Section. () (2) Preorder, Postorder and Levelorder Traversals Definition: A tree is a connected graph with no cycles Consequences: Between any two vertices, there is exactly one unique path

More information

APT Session 2: Python

APT Session 2: Python APT Session 2: Python Laurence Tratt Software Development Team 2017-10-20 1 / 17 http://soft-dev.org/ What to expect from this session: Python 1 What is Python? 2 Basic Python functionality. 2 / 17 http://soft-dev.org/

More information

jxmlease Documentation

jxmlease Documentation jxmlease Documentation Release 1.0.2dev1 Juniper Networks April 18, 2016 Contents 1 Welcome 1 1.1 Installation................................................ 1 1.2 Parsing XML...............................................

More information

Python Essential Reference, Second Edition - Chapter 5: Control Flow Page 1 of 8

Python Essential Reference, Second Edition - Chapter 5: Control Flow Page 1 of 8 Python Essential Reference, Second Edition - Chapter 5: Control Flow Page 1 of 8 Chapter 5: Control Flow This chapter describes related to the control flow of a program. Topics include conditionals, loops,

More information

Python Basics. Lecture and Lab 5 Day Course. Python Basics

Python Basics. Lecture and Lab 5 Day Course. Python Basics Python Basics Lecture and Lab 5 Day Course Course Overview Python, is an interpreted, object-oriented, high-level language that can get work done in a hurry. A tool that can improve all professionals ability

More information

Recursion. Presentation Subtitle. Brad Miller David Ranum 1 12/19/2005. Luther College. Binary Search Trees. 1 Department of Computer Science

Recursion. Presentation Subtitle. Brad Miller David Ranum 1 12/19/2005. Luther College. Binary Search Trees. 1 Department of Computer Science Presentation Subtitle Brad Miller David Ranum 1 1 Department of Computer Science Luther College 12/19/2005 Outline 1 Binary Search Trees Outline Binary Search Trees 1 Binary Search Trees BinaryTree() Create

More information

Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines.

Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines. Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of

More information

Lecture #12: Quick: Exceptions and SQL

Lecture #12: Quick: Exceptions and SQL UC Berkeley EECS Adj. Assistant Prof. Dr. Gerald Friedland Computational Structures in Data Science Lecture #12: Quick: Exceptions and SQL Administrivia Open Project: Starts Monday! Creative data task

More information

Beyond Blocks: Python Session #1

Beyond Blocks: Python Session #1 Beyond Blocks: Session #1 CS10 Spring 2013 Thursday, April 30, 2013 Michael Ball Beyond Blocks : : Session #1 by Michael Ball adapted from Glenn Sugden is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike

More information

CIS192 Python Programming

CIS192 Python Programming CIS192 Python Programming Generators Exceptions and IO Eric Kutschera University of Pennsylvania February 13, 2015 Eric Kutschera (University of Pennsylvania) CIS 192 February 13, 2015 1 / 24 Outline 1

More information

ENGR 102 Engineering Lab I - Computation

ENGR 102 Engineering Lab I - Computation ENGR 102 Engineering Lab I - Computation Learning Objectives by Week 1 ENGR 102 Engineering Lab I Computation 2 Credits 2. Introduction to the design and development of computer applications for engineers;

More information

n 1 i = n + i = n + f(n 1)

n 1 i = n + i = n + f(n 1) 2 Binary Search Trees Lab Objective: A tree is a linked list where each node in the list may refer to more than one other node. This structural flexibility makes trees more useful and efficient than regular

More information

TAIL RECURSION, SCOPE, AND PROJECT 4 11

TAIL RECURSION, SCOPE, AND PROJECT 4 11 TAIL RECURSION, SCOPE, AND PROJECT 4 11 COMPUTER SCIENCE 61A Noveber 12, 2012 1 Tail Recursion Today we will look at Tail Recursion and Tail Call Optimizations in Scheme, and how they relate to iteration

More information

Index. Cache, 20 Callables, 185 call () method, 290 chain() function, 41 Classes attributes descriptors, 145 properties, 143

Index. Cache, 20 Callables, 185 call () method, 290 chain() function, 41 Classes attributes descriptors, 145 properties, 143 Index A add_column() method, 284 add() method, 44 addtypeequalityfunc() method, 253 Affero General Public License (AGPL), 260 American Standard Code for Information Interchange (ASCII), 218 219 and operator,

More information

MEMOIZATION, RECURSIVE DATA, AND SETS

MEMOIZATION, RECURSIVE DATA, AND SETS MEMOIZATION, RECURSIVE DATA, AND SETS 4b COMPUTER SCIENCE 61A July 18, 2013 1 Memoization Later in this class, you ll learn about orders of growth and how to analyze exactly how efficient (or inefficient)

More information

Interactive use. $ python. >>> print 'Hello, world!' Hello, world! >>> 3 $ Ctrl-D

Interactive use. $ python. >>> print 'Hello, world!' Hello, world! >>> 3 $ Ctrl-D 1/58 Interactive use $ python Python 2.7.5 (default, Mar 9 2014, 22:15:05) [GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin Type "help", "copyright", "credits" or "license" for more information.

More information

Pypeline Documentation

Pypeline Documentation Pypeline Documentation Release 0.2 Kyle Corbitt May 09, 2014 Contents 1 Contents 3 1.1 Installation................................................ 3 1.2 Quick Start................................................

More information

INTERPRETERS 8. 1 Calculator COMPUTER SCIENCE 61A. November 3, 2016

INTERPRETERS 8. 1 Calculator COMPUTER SCIENCE 61A. November 3, 2016 INTERPRETERS 8 COMPUTER SCIENCE 61A November 3, 2016 1 Calculator We are beginning to dive into the realm of interpreting computer programs that is, writing programs that understand other programs. In

More information

PREPARING FOR PRELIM 1

PREPARING FOR PRELIM 1 PREPARING FOR PRELIM 1 CS 1110: FALL 2012 This handout explains what you have to know for the first prelim. There will be a review session with detailed examples to help you study. To prepare for the prelim,

More information

There are four numeric types: 1. Integers, represented as a 32 bit (or longer) quantity. Digits sequences (possibly) signed are integer literals:

There are four numeric types: 1. Integers, represented as a 32 bit (or longer) quantity. Digits sequences (possibly) signed are integer literals: Numeric Types There are four numeric types: 1. Integers, represented as a 32 bit (or longer) quantity. Digits sequences (possibly) signed are integer literals: 1-123 +456 2. Long integers, of unlimited

More information

Interactive use. $ python. >>> print 'Hello, world!' Hello, world! >>> 3 $ Ctrl-D

Interactive use. $ python. >>> print 'Hello, world!' Hello, world! >>> 3 $ Ctrl-D 1/60 Interactive use $ python Python 2.7.5 (default, Mar 9 2014, 22:15:05) [GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin Type "help", "copyright", "credits" or "license" for more information.

More information

tld Documentation Release 0.9 Artur Barseghyan

tld Documentation Release 0.9 Artur Barseghyan tld Documentation Release 0.9 Artur Barseghyan Jun 13, 2018 Contents 1 Prerequisites 3 2 Documentation 5 3 Installation 7 4 Usage examples 9 5 Update the list of TLD names

More information

Table of Contents EVALUATION COPY

Table of Contents EVALUATION COPY Table of Contents Introduction... 1-2 A Brief History of Python... 1-3 Python Versions... 1-4 Installing Python... 1-5 Environment Variables... 1-6 Executing Python from the Command Line... 1-7 IDLE...

More information

redis-lua Documentation

redis-lua Documentation redis-lua Documentation Release 2.0.8 Julien Kauffmann October 12, 2016 Contents 1 Quick start 3 1.1 Step-by-step analysis........................................... 3 2 What s the magic at play here?

More information

Structure and Interpretation of Computer Programs Summer 2015 Midterm 2

Structure and Interpretation of Computer Programs Summer 2015 Midterm 2 CS 6A Structure and Interpretation of Computer Programs Summer 05 Midterm INSTRUCTIONS You have hours to complete the exam. The exam is closed book, closed notes, closed computer, closed calculator, except

More information

Software Development Python (Part B)

Software Development Python (Part B) Software Development Python (Part B) Davide Balzarotti Eurecom 1 List Comprehension It is a short way to construct a list based on the content of other existing lists Efficient Elegant Concise List comprehensions

More information

CS 11 python track: lecture 4

CS 11 python track: lecture 4 CS 11 python track: lecture 4 Today: More odds and ends assertions "print >>" syntax more on argument lists functional programming tools list comprehensions More on exception handling More on object-oriented

More information

DATA STRUCTURE AND ALGORITHM USING PYTHON

DATA STRUCTURE AND ALGORITHM USING PYTHON DATA STRUCTURE AND ALGORITHM USING PYTHON Advanced Data Structure and File Manipulation Peter Lo Linear Structure Queue, Stack, Linked List and Tree 2 Queue A queue is a line of people or things waiting

More information

About Python. Python Duration. Training Objectives. Training Pre - Requisites & Who Should Learn Python

About Python. Python Duration. Training Objectives. Training Pre - Requisites & Who Should Learn Python About Python Python course is a great introduction to both fundamental programming concepts and the Python programming language. By the end, you'll be familiar with Python syntax and you'll be able to

More information

databuild Documentation

databuild Documentation databuild Documentation Release 0.0.10 Flavio Curella May 15, 2015 Contents 1 Contents 3 1.1 Installation................................................ 3 1.2 Quickstart................................................

More information

Webgurukul Programming Language Course

Webgurukul Programming Language Course Webgurukul Programming Language Course Take One step towards IT profession with us Python Syllabus Python Training Overview > What are the Python Course Pre-requisites > Objectives of the Course > Who

More information

TREES AND ORDERS OF GROWTH 7

TREES AND ORDERS OF GROWTH 7 TREES AND ORDERS OF GROWTH 7 COMPUTER SCIENCE 61A October 17, 2013 1 Trees In computer science, trees are recursive data structures that are widely used in various settings. This is a diagram of a simple

More information

Interpreters and Tail Calls Fall 2017 Discussion 8: November 1, 2017 Solutions. 1 Calculator. calc> (+ 2 2) 4

Interpreters and Tail Calls Fall 2017 Discussion 8: November 1, 2017 Solutions. 1 Calculator. calc> (+ 2 2) 4 CS 61A Interpreters and Tail Calls Fall 2017 Discussion 8: November 1, 2017 Solutions 1 Calculator We are beginning to dive into the realm of interpreting computer programs that is, writing programs that

More information

Figure 1: A complete binary tree.

Figure 1: A complete binary tree. The Binary Heap A binary heap is a data structure that implements the abstract data type priority queue. That is, a binary heap stores a set of elements with a total order (that means that every two elements

More information

Structure and Interpretation of Computer Programs

Structure and Interpretation of Computer Programs CS 6A Summer 5 Structure and Interpretation of Computer Programs Midterm Solutions INSTRUCTIONS You have hours to complete the exam. The exam is closed book, closed notes, closed computer, closed calculator,

More information

Iterators & Generators

Iterators & Generators Iterators & Generators Sequences A sequence is something that you can: Index into Get the length of What are some examples of sequences? Sequences We ve been working with sequences all semester! Examples:

More information

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of

More information

Sequences and iteration in Python

Sequences and iteration in Python GC3: Grid Computing Competence Center Sequences and iteration in Python GC3: Grid Computing Competence Center, University of Zurich Sep. 11 12, 2013 Sequences Python provides a few built-in sequence classes:

More information

Summer 2017 Discussion 10: July 25, Introduction. 2 Primitives and Define

Summer 2017 Discussion 10: July 25, Introduction. 2 Primitives and Define CS 6A Scheme Summer 207 Discussion 0: July 25, 207 Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme programs,

More information

Course Title: Python + Django for Web Application

Course Title: Python + Django for Web Application Course Title: Python + Django for Web Application Duration: 6 days Introduction This course offer Python + Django framework ( MTV ) training with hands on session using Eclipse+Pydev Environment. Python

More information

redish Documentation Release Ask Solem

redish Documentation Release Ask Solem redish Documentation Release 0.2.0 Ask Solem Sep 14, 2017 Contents 1 redish - Pythonic Redis abstraction built on top of redis-py 3 1.1 Introduction............................................... 3 1.2

More information

django-crucrudile Documentation

django-crucrudile Documentation django-crucrudile Documentation Release 0.9.1 Hugo Geoffroy (pstch) July 27, 2014 Contents 1 Installation 1 1.1 From Python package index....................................... 1 1.2 From source...............................................

More information

Django Extra Views Documentation

Django Extra Views Documentation Django Extra Views Documentation Release 0.12.0 Andrew Ingram Nov 30, 2018 Contents 1 Features 3 2 Table of Contents 5 2.1 Getting Started.............................................. 5 2.2 Formset Views..............................................

More information

CSC148H Week 8. Sadia Sharmin. July 12, /29

CSC148H Week 8. Sadia Sharmin. July 12, /29 CSC148H Week 8 Sadia Sharmin July 12, 2017 1/29 Motivating Trees I A data structure is a way of organizing data I Stacks, queues, and lists are all linear structures I They are linear in the sense that

More information

Cross-platform daemonization tools.

Cross-platform daemonization tools. Cross-platform daemonization tools. Release 0.1.0 Muterra, Inc Sep 14, 2017 Contents 1 What is Daemoniker? 1 1.1 Installing................................................. 1 1.2 Example usage..............................................

More information

PYTHON CONTENT NOTE: Almost every task is explained with an example

PYTHON CONTENT NOTE: Almost every task is explained with an example PYTHON CONTENT NOTE: Almost every task is explained with an example Introduction: 1. What is a script and program? 2. Difference between scripting and programming languages? 3. What is Python? 4. Characteristics

More information

CIS192 Python Programming

CIS192 Python Programming CIS192 Python Programming Functional Programming Robert Rand University of Pennsylvania February 03, 2016 Robert Rand (University of Pennsylvania) CIS 192 February 03, 2016 1 / 23 Outline 1 Function Arguments

More information

MongoTor Documentation

MongoTor Documentation MongoTor Documentation Release 0.1.0 Marcel Nicolat June 11, 2014 Contents 1 Features 3 2 Contents: 5 2.1 Installation................................................ 5 2.2 Tutorial..................................................

More information

What we already know. more of what we know. results, searching for "This" 6/21/2017. chapter 14

What we already know. more of what we know. results, searching for This 6/21/2017. chapter 14 What we already know chapter 14 Files and Exceptions II Files are bytes on disk. Two types, text and binary (we are working with text) open creates a connection between the disk contents and the program

More information

The Practice of Computing Using PYTHON

The Practice of Computing Using PYTHON The Practice of Computing Using PYTHON William Punch Richard Enbody Chapter 6 Lists and Tuples 1 Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Data Structures 2 Data Structures

More information

COMP : Trees. COMP20012 Trees 219

COMP : Trees. COMP20012 Trees 219 COMP20012 3: Trees COMP20012 Trees 219 Trees Seen lots of examples. Parse Trees Decision Trees Search Trees Family Trees Hierarchical Structures Management Directories COMP20012 Trees 220 Trees have natural

More information

PYTHON FOR KIDS A Pl ayfu l I ntrodu ctio n to Prog r am m i ng J a s o n R. B r i g g s

PYTHON FOR KIDS A Pl ayfu l I ntrodu ctio n to Prog r am m i ng J a s o n R. B r i g g s PYTHON FO R K I D S A P l ay f u l I n t r o d u c t i o n to P r o g r a m m i n g Jason R. Briggs Index Symbols and Numbers + (addition operator), 17 \ (backslash) to separate lines of code, 235 in strings,

More information

Introduction to Python

Introduction to Python Introduction to Python Version 1.1.5 (12/29/2008) [CG] Page 1 of 243 Introduction...6 About Python...7 The Python Interpreter...9 Exercises...11 Python Compilation...12 Python Scripts in Linux/Unix & Windows...14

More information

CIS192 Python Programming

CIS192 Python Programming CIS192 Python Programming Functional Programming Eric Kutschera University of Pennsylvania January 30, 2015 Eric Kutschera (University of Pennsylvania) CIS 192 January 30, 2015 1 / 31 Questions Homework

More information

1 Decorators. 2 Descriptors. 3 Static Variables. 4 Anonymous Classes. Sandeep Sadanandan (TU, Munich) Python For Fine Programmers July 13, / 19

1 Decorators. 2 Descriptors. 3 Static Variables. 4 Anonymous Classes. Sandeep Sadanandan (TU, Munich) Python For Fine Programmers July 13, / 19 1 Decorators 2 Descriptors 3 Static Variables 4 Anonymous Classes Sandeep Sadanandan (TU, Munich) Python For Fine Programmers July 13, 2009 1 / 19 Decorator Pattern In object-oriented programming, the

More information

Packtools Documentation

Packtools Documentation Packtools Documentation Release 2.1 SciELO Sep 28, 2017 Contents 1 User guide 3 1.1 Installing Packtools........................................... 3 1.2 Tutorial..................................................

More information

TUPLES AND RECURSIVE LISTS 5

TUPLES AND RECURSIVE LISTS 5 TUPLES AND RECURSIVE LISTS 5 COMPUTER SCIENCE 61A July 3, 2012 1 Sequences From the Pig project, we discovered the utility of having structures that contain multiple values. Today, we are going to cover

More information

Princeton University COS 333: Advanced Programming Techniques A Subset of Python 2.7

Princeton University COS 333: Advanced Programming Techniques A Subset of Python 2.7 Princeton University COS 333: Advanced Programming Techniques A Subset of Python 2.7 Program Structure # Print "hello world" to stdout. print 'hello, world' # Print "hello world" to stdout. def f(): print

More information

Python Interview Questions & Answers

Python Interview Questions & Answers Python Interview Questions & Answers Q 1: What is Python? Ans: Python is an interpreted, interactive, object-oriented programming language. It incorporates modules, exceptions, dynamic typing, very high

More information

CS 11 python track: lecture 3. n Today: Useful coding idioms

CS 11 python track: lecture 3. n Today: Useful coding idioms CS 11 python track: lecture 3 Today: Useful coding idioms Useful coding idioms "Idiom" Standard ways of accomplishing a common task Using standard idioms won't make your code more correct, but more concise

More information

Part 1: jquery & History of DOM Scripting

Part 1: jquery & History of DOM Scripting Karl Swedberg: Intro to JavaScript & jquery 0:00:00 0:05:00 0:05:01 0:10:15 0:10:16 0:12:36 0:12:37 0:13:32 0:13:32 0:14:16 0:14:17 0:15:42 0:15:43 0:16:59 0:17:00 0:17:58 Part 1: jquery & History of DOM

More information

Mastering Python Decorators

Mastering Python Decorators Mastering Python Decorators One of the hallmarks of good Python is the judicious use of decorators to optimize, simplify and add new functionality to existing code. Decorators are usually seen as an advanced

More information

CNRS ANF PYTHON Objects everywhere

CNRS ANF PYTHON Objects everywhere CNRS ANF PYTHON Objects everywhere Marc Poinot Numerical Simulation Dept. Outline Python Object oriented features Basic OO concepts syntax More on Python classes multiple inheritance reuse introspection

More information

Structure and Interpretation of Computer Programs

Structure and Interpretation of Computer Programs CS 61A Summer 2014 Structure and Interpretation of Computer Programs Final Solutions INSTRUCTIONS ˆ You have 3 hours to complete the exam. ˆ The exam is closed book, closed notes, and closed electronics,

More information

funcsigs Documentation

funcsigs Documentation funcsigs Documentation Release 0.4 Aaron Iles December 20, 2013 Contents i ii CHAPTER 1 The Funcsigs Package funcsigs is a backport of the PEP 362 function signature features from Python 3.3 s inspect

More information

Introduction to Python Part 2

Introduction to Python Part 2 Introduction to Python Part 2 v0.2 Brian Gregor Research Computing Services Information Services & Technology Tutorial Outline Part 2 Functions Tuples and dictionaries Modules numpy and matplotlib modules

More information

https://lambda.mines.edu Why study Python in Principles of Programming Languages? Multi-paradigm Object-oriented Functional Procedural Dynamically typed Relatively simple with little feature multiplicity

More information

TREES AND ORDERS OF GROWTH 7

TREES AND ORDERS OF GROWTH 7 TREES AND ORDERS OF GROWTH 7 COMPUTER SCIENCE 61A March 12, 2015 1 Trees in OOP 1.1 Our Implementation Previously, we have seen trees defined as an abstract data type using lists. Let s look at another

More information

semidbm Documentation

semidbm Documentation semidbm Documentation Release 0.4.0 James Saryerwinnie Jr September 04, 2013 CONTENTS i ii semidbm is a pure python implementation of a dbm, which is essentially a persistent key value store. It allows

More information

CSE : Python Programming

CSE : Python Programming CSE 399-004: Python Programming Lecture 08: Graphical User Interfaces with wxpython March 12, 2005 http://www.seas.upenn.edu/~cse39904/ Plan for today and next time Today: wxpython (part 1) Aside: Arguments

More information

LECTURE 3 Python Basics Part 2

LECTURE 3 Python Basics Part 2 LECTURE 3 Python Basics Part 2 FUNCTIONAL PROGRAMMING TOOLS Last time, we covered function concepts in depth. We also mentioned that Python allows for the use of a special kind of function, a lambda function.

More information

UNINFORMED SEARCH. Announcements Reading Section 3.4, especially 3.4.1, 3.4.2, 3.4.3, 3.4.5

UNINFORMED SEARCH. Announcements Reading Section 3.4, especially 3.4.1, 3.4.2, 3.4.3, 3.4.5 UNINFORMED SEARCH Announcements Reading Section 3.4, especially 3.4.1, 3.4.2, 3.4.3, 3.4.5 Robbie has no idea where room X is, and may have little choice but to try going down this corridor and that. On

More information

CSI33 Data Structures

CSI33 Data Structures Outline Department of Mathematics and Computer Science Bronx Community College September 25, 2017 Outline Outline 1 Chapter 4: Linked Structures and Chapter 4: Linked Structures and Outline 1 Chapter 4:

More information

List of squares. Program to generate a list containing squares of n integers starting from 0. list. Example. n = 12

List of squares. Program to generate a list containing squares of n integers starting from 0. list. Example. n = 12 List of squares Program to generate a list containing squares of n integers starting from 0 Example list n = 12 squares = [] for i in range(n): squares.append(i**2) print(squares) $ python3 squares.py

More information

Lecture 5: Suffix Trees

Lecture 5: Suffix Trees Longest Common Substring Problem Lecture 5: Suffix Trees Given a text T = GGAGCTTAGAACT and a string P = ATTCGCTTAGCCTA, how do we find the longest common substring between them? Here the longest common

More information

CIS192: Python Programming

CIS192: Python Programming CIS192: Python Programming Functions and Functional Programming Harry Smith University of Pennsylvania January 25, 2018 Harry Smith (University of Pennsylvania) CIS 192 Lecture 3 January 25, 2018 1 / 39

More information

Python Training. Complete Practical & Real-time Trainings. A Unit of SequelGate Innovative Technologies Pvt. Ltd.

Python Training. Complete Practical & Real-time Trainings. A Unit of SequelGate Innovative Technologies Pvt. Ltd. Python Training Complete Practical & Real-time Trainings A Unit of. ISO Certified Training Institute Microsoft Certified Partner Training Highlights : Complete Practical and Real-time Scenarios Session

More information

Friday Four Square! 4:15PM, Outside Gates

Friday Four Square! 4:15PM, Outside Gates Binary Search Trees Friday Four Square! 4:15PM, Outside Gates Implementing Set On Monday and Wednesday, we saw how to implement the Map and Lexicon, respectively. Let's now turn our attention to the Set.

More information

ECE 2400 Computer Systems Programming, Fall 2017 Prelim 2 Prep

ECE 2400 Computer Systems Programming, Fall 2017 Prelim 2 Prep revision: 2017-11-04-22-45 These problems are not meant to be exactly like the problems that will be on the prelim. These problems are instead meant to represent the kind of understanding you should be

More information

SMQTK Documentation. Release Kitware, Inc.

SMQTK Documentation. Release Kitware, Inc. SMQTK Documentation Release 0.3.0 Kitware, Inc. February 09, 2016 Contents 1 Building SMQTK 3 1.1 Dependencies............................................... 3 1.2 Build...................................................

More information

Complete Python call :

Complete Python call : Module 1 (Baics Python Rs.4000 ) 30 hours CHAPTER Instant Hacking: The Basics Installing Python Windows Linux and UNIX Macintosh Other Distributions Keeping In Touch and Up to Date The Interactive Interpreter

More information