This document provides an overview of the Python programming language and its capabilities for functional programming. It describes Python's attributes such as being portable, object-oriented, and supporting procedural, object-oriented, and functional programming. It also lists several popular Python modules that provide additional functionality and examples of code written in both a procedural and object-oriented style in Python. Finally, it provides examples of functional programming concepts like map, filter and reduce implemented in Python along with references for further information.
Functional Python Webinar from October 22nd, 2014Reuven Lerner
Slides from my free functional Python webinar, given on October 22nd, 2014. Discussion included functional programming as a perspective, passing functions as data, and writing programs that take functions as parameters. Includes (at the end) a coupon for my new ebook, Practice Makes Python.
Using functional concepts in Python. Introduction to functional programming and exploring each of the concepts, like map, filter and reduce in detail and how functional programming can help creating massively parallel software systems
following is work on Advance Python part 1 Functional Programming in Python
for code and more details plz do visit
https://lnkd.in/dnQF95z
for more free study material and Projects follow on
Github
https://lnkd.in/gYKtuB3
LinkedIn
https://lnkd.in/daSvf_P
#python #datascience #programming #machinelearning #github #deeplearning #coding #developer #projects #work #developers #linkedin #google #amazonindia#IBM
Functional Python Webinar from October 22nd, 2014Reuven Lerner
Slides from my free functional Python webinar, given on October 22nd, 2014. Discussion included functional programming as a perspective, passing functions as data, and writing programs that take functions as parameters. Includes (at the end) a coupon for my new ebook, Practice Makes Python.
Using functional concepts in Python. Introduction to functional programming and exploring each of the concepts, like map, filter and reduce in detail and how functional programming can help creating massively parallel software systems
following is work on Advance Python part 1 Functional Programming in Python
for code and more details plz do visit
https://lnkd.in/dnQF95z
for more free study material and Projects follow on
Github
https://lnkd.in/gYKtuB3
LinkedIn
https://lnkd.in/daSvf_P
#python #datascience #programming #machinelearning #github #deeplearning #coding #developer #projects #work #developers #linkedin #google #amazonindia#IBM
Python Functions Tutorial | Working With Functions In Python | Python Trainin...Edureka!
** Python Certification Training: https://www.edureka.co/python **
This Edureka PPT on Python Functions tutorial covers all the important aspects of functions in Python right from the introduction to what functions are, all the way till checking out the major functions and using the code-first approach to understand them better.
Agenda
Why use Functions?
What are the Functions?
Types of Python Functions
Built-in Functions in Python
User-defined Functions in Python
Python Lambda Function
Conclusion
Python Tutorial Playlist: https://goo.gl/WsBpKe
Blog Series: http://bit.ly/2sqmP4s
Follow us to never miss an update in the future.
Instagram: https://www.instagram.com/edureka_learning/
Facebook: https://www.facebook.com/edurekaIN/
Twitter: https://twitter.com/edurekain
LinkedIn: https://www.linkedin.com/company/edureka
This is continuation of the slide Advanced C part 1. In part 1 you learnt about fundamentals of C - How to build an algorithm, operators. In this module - Advanced C part 2 you will be learning about functions, pointers and standard Input Output functions. This slide will help you to move a further ahead in Advanced C and gain deeper knowledge on it.
It tells about functions in C++,Types,Use,prototype,declaration,Arguments etc
function with
A function with no parameter and no return value
A function with parameter and no return value
A function with parameter and return value
A function without parameter and return value
Call by value and address
Types of C++ functions:
Standard functions
User-defined functions
C++ function structure
Function signature
Function body
Declaring and Implementing C++ functions
Try to imagine the amount of time and effort it would take you to write a bug-free script or application that will accept a URL, port scan it, and for each HTTP service that it finds, it will create a new thread and perform a black box penetration testing while impersonating a Blackberry 9900 smartphone. While you’re thinking, Here’s how you would have done it in Hackersh:
“http://localhost” \
-> url \
-> nmap \
-> browse(ua=”Mozilla/5.0 (BlackBerry; U; BlackBerry 9900; en) AppleWebKit/534.11+ (KHTML, like Gecko) Version/7.1.0.346 Mobile Safari/534.11+”) \
-> w3af
Meet Hackersh (“Hacker Shell”) – A new, free and open source cross-platform shell (command interpreter) with built-in security commands and Pythonect-like syntax.
Aside from being interactive, Hackersh is also scriptable with Pythonect. Pythonect is a new, free, and open source general-purpose dataflow programming language based on Python, written in Python. Hackersh is inspired by Unix pipeline, but takes it a step forward by including built-in features like remote invocation and threads. This 120 minute lab session will introduce Hackersh, the automation gap it fills, and its features. Lots of demonstrations and scripts are included to showcase concepts and ideas.
Python Functions Tutorial | Working With Functions In Python | Python Trainin...Edureka!
** Python Certification Training: https://www.edureka.co/python **
This Edureka PPT on Python Functions tutorial covers all the important aspects of functions in Python right from the introduction to what functions are, all the way till checking out the major functions and using the code-first approach to understand them better.
Agenda
Why use Functions?
What are the Functions?
Types of Python Functions
Built-in Functions in Python
User-defined Functions in Python
Python Lambda Function
Conclusion
Python Tutorial Playlist: https://goo.gl/WsBpKe
Blog Series: http://bit.ly/2sqmP4s
Follow us to never miss an update in the future.
Instagram: https://www.instagram.com/edureka_learning/
Facebook: https://www.facebook.com/edurekaIN/
Twitter: https://twitter.com/edurekain
LinkedIn: https://www.linkedin.com/company/edureka
This is continuation of the slide Advanced C part 1. In part 1 you learnt about fundamentals of C - How to build an algorithm, operators. In this module - Advanced C part 2 you will be learning about functions, pointers and standard Input Output functions. This slide will help you to move a further ahead in Advanced C and gain deeper knowledge on it.
It tells about functions in C++,Types,Use,prototype,declaration,Arguments etc
function with
A function with no parameter and no return value
A function with parameter and no return value
A function with parameter and return value
A function without parameter and return value
Call by value and address
Types of C++ functions:
Standard functions
User-defined functions
C++ function structure
Function signature
Function body
Declaring and Implementing C++ functions
Try to imagine the amount of time and effort it would take you to write a bug-free script or application that will accept a URL, port scan it, and for each HTTP service that it finds, it will create a new thread and perform a black box penetration testing while impersonating a Blackberry 9900 smartphone. While you’re thinking, Here’s how you would have done it in Hackersh:
“http://localhost” \
-> url \
-> nmap \
-> browse(ua=”Mozilla/5.0 (BlackBerry; U; BlackBerry 9900; en) AppleWebKit/534.11+ (KHTML, like Gecko) Version/7.1.0.346 Mobile Safari/534.11+”) \
-> w3af
Meet Hackersh (“Hacker Shell”) – A new, free and open source cross-platform shell (command interpreter) with built-in security commands and Pythonect-like syntax.
Aside from being interactive, Hackersh is also scriptable with Pythonect. Pythonect is a new, free, and open source general-purpose dataflow programming language based on Python, written in Python. Hackersh is inspired by Unix pipeline, but takes it a step forward by including built-in features like remote invocation and threads. This 120 minute lab session will introduce Hackersh, the automation gap it fills, and its features. Lots of demonstrations and scripts are included to showcase concepts and ideas.
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...DRVaibhavmeshram1
Python
Language
is uesd in engineeringStory adapted from Stephen Covey (2004) “The Seven Habits of Highly Effective People” Simon & Schuster).
“Management is doing things right, leadership is doing the right things”
(Warren Bennis and Peter Drucker)
Story adapted from Stephen Covey (2004) “The Seven Habits of Highly Effective People” Simon & Schuster).
“Management is doing things right, leadership is doing the right things”
(Warren Bennis and Peter Drucker)
Story adapted from Stephen Covey (2004) “The Seven Habits of Highly Effective People” Simon & Schuster).
“Management is doing things right, leadership is doing the right things”
(Warren Bennis and Peter Drucker)
The Sponsor:
Champion and advocates for the change at their level in the organization.
A Sponsor is the person who won’t let the change initiative die from lack of attention, and is willing to use their political capital to make the change happen
The Role model:
Behaviors and attitudes demonstrated by them are looked upon by everyone else. . Hence, they must be willing to go first.
Employees watch leaders for consistency between words and actions to see if they should believe the change is really going to happen.
The decision maker:
Leaders usually control resources such as people, budgets, and equipment, and thus have the authority to make decisions (as per their span of control) that affect the initiative.
During change, leaders must leverage their decision-making authority and choose the options that will support the initiative.
The Decision-Maker is decisive and sets priorities that support change.
The Sponsor:
Champion and advocates for the change at their level in the organization.
A Sponsor is the person who won’t let the change initiative die from lack of attention, and is willing to use their political capital to make the change happen
The Role model:
Behaviors and attitudes demonstrated by them are looked upon by everyone else. . Hence, they must be willing to go first.
Employees watch leaders for consistency between words and actions to see if they should believe the change is really going to happen.
The decision maker:
Leaders usually control resources such as people, budgets, and equipment, and thus have the authority to make decisions (as per their span of control) that affect the initiative.
During change, leaders must leverage their decision-making authority and choose the options that will support the initiative.
The Decision-Maker is decisive and sets priorities that support change.
The Sponsor:
Champion and advocates for the change at their level in the organization.
A Sponsor is the person who won’t let the change initiative die from lack of attention, and is willing to use their political capital to make the change happen
The Role model:
Behaviors and attitudes demonstrated by them are looked upon by everyone else. . Hence, they must be willing to go first.
Employees watch leaders for consistency between words and actions to see if they s
Material ini digunakan untuk kelas teknologi pengenalan pemrograman dengan bahasa pengantar Python http://oo.or.id/py
Dipublikasikan dengan lisensi Atribusi-Berbagi Serupa Creative Commons (CC BY-SA) oleh oon@oo.or.id
PCI Compliance in the Cloud: A working exampleAdam Getchell
The Giving website (https://give.ucdavis.edu) processes all online gifts for UC Davis and the UC Davis Medical Center, runs on Azure, and passed PCI DSS 3.0. We'll show you how we did it.
I review how to derive Newtons law of universal gravitation from the Weyl strut between two Chazy-Curzon particles. I also briefly review Causal Dynamical Triangulations (CDT), a method for evaluating the path integral from canonical quantum gravity using Regge calculus and restrictions of the class of simplicial manifolds evaluated to those with a defined time foliation, thus enforcing a causal structure. I then discuss how to apply this approach to Causal Dynamical Triangulations, in particular modifying the algorithm to keep two simplicial submanifolds with curvature (i.e. mass) a fixed distance from each other, modulo regularized deviations and across all time slices. I then discuss how to determine if CDT produces an equivalent Weyl strut, which can then be used to obtain the Newtonian limit. I wrap up with a brief discussion of computational methods and code development.
I summarize two years of practical experience developing campus-wide business applications on Microsoft's Azure platform. Our results are more rapid application development, better uptime and disaster recovery, and infrastructure costs two orders of magnitude lower than traditional on-premises solutions.
1. An Overview of Python with
Functional Programming
Adam Getchell
PHY 210
2. Attributes
• Portable, interpreted, object-oriented, strongly- and dynamically-typed, extensible
– Can write extensions to Python in C/C++
– Links to operating system functions using modules
• Open sourced, developed and supported by the Python Organization (http://www.python.org)
• Freely available on most platforms (Windows, Unix, Linux, *BSD, MacOS)
• Supports procedural, object-oriented, and functional programming
• Huge number of add-on modules available
– Numarray provides capabilities similar to MatLab, IDL, or Octave
• http://www.stsci.edu/resources/software_hardware/numarray
– SciPy implements plotting, parallel computation, FFT, ODE solvers, and linear algebra/LAPACK/BLAS routines from
http://www.netlib.org using thin python wrappers over C or FORTRAN code (and using WEAVE allows direct inlining
of C/C++ code within Python)
• http://www.scipy.org/
– mxODBC provides ODBC database connectivity (e.g. Oracle, SQLServer, mySQL, PostgreSQL, DB2, Sybase)
• http://www.egenix.com/files/python/mxODBC.html
– ReportLab Open Source PDF Library generates PDF files
• http://www.reportlab.org/
– PyXML parses/handles XML with DOM, SAX, XPath/XPointer
• http://pyxml.sourceforge.net/topics/download.html
– Jython implements Python on top of Java, gaining access to the Java platform with Python syntax
• http://www.jython.org
– wxPython implements a cross-platform GUI library for GUI applications
• http://www.wxpython.org/
– MatPlotLib is a cross platform Python 2D plotting library which produces publication quality figures in a variety of
hardcopy formats and interactive GUI environments
• http://matplotlib.sourceforge.net
• Runs large-scale software projects
– Google
– Hubble Space Telescope data processing pipeline
– Zope and Plone
3. Tokens and Structure
Code Pattern C Python
Statements Unlimited length, terminated with “;”
Code blocks delineated by { }
One statement per line, unless explicitly joined by or implicitly joined across (), [], or {}
Code blocks delineated by indentation level (tabs)
Comment /* Comment */ # Comment to end of line unless line joined implicitly
Variables Explicitly declared (statically typed)
int, long int, double, float, etc
Objects have identity, type, and value. Identity is memory address, type determines
supported methods and whether the object can be changed (mutable).
Variables dynamically typed at runtime
Boolean, int (equivalent to long), decimal, float, imaginary, Iterators, strings, Unicode
strings, tuples, lists, buffers, xrange, set, frozenset, dictionaries,
Scoping Global variables declared prior to main()
Local variables declared in each procedure
Statically scoped block structure (local, global, built-in) with static lexical scoping. Lexical
scoping defaults to namespace of enclosing function or class
Functions Type and arguments declared Name and parameters must be declared; can take variable list of arguments using varargs()
Functions are first-class elements of language supporting Functional Programming using List
Comprehensions, lambda, map(), reduce(), filter() and Generators with yield()
Matrices A[i][j] Vector = array([1,2,3,4,5]) # from numarray
Matrix = array([1,2],[3,4]) # from numarray
Tuple = ( 1, 2, “three” ) # immutable, ordered, faster than list
List = [ 4, 5, Tuple ] # mutable, ordered, expands dynamically as needed
Dictionary = { “key1”: “value1”, “key2”: “value2” } # mutable, unordered
Open Files Input_file=fopen(filename, “r”)
Output_file=fopen(filename, “w”)
f = open("/music/_singles/kairo.mp3", "rb") # read binary mode
g = open(“/temp/outputfile.txt”, “a”) # append mode
h = open(“/temp/outputfile.txt”, “w”) # overwrite mode
Input scanf(stdin, “ %lf “, &var)
fscanf(input_file, “ %lf “, &var)
s = raw_input(“Who goes there?”) or sys.stdin.readline()
s = f.read() or f.readlines()
Output printf(stdout, “ %lf “, var)
printf(stdout, “ %lf “, var)
print s
Relational
Operators
==, >=, <=, !=, <, > Python supports operator overloading
==,>=,<=,!=,<>, <, >, is, is not
Logical Operators &&, ||, ! and, or, not
Bitwise Operators &, |, ^, ~, >>, << &, |, ^, ~, >>, <<
4. Tokens and Structure part II
Code Pattern C Python
Pointers Declaration: int *p (p is the address of an
integer, it points to an integer)
int *p, value, var;
var = 10;
p = &var;
Value = *p (Value = 10)
Python does not directly have pointers
However, everything in Python is an object
Objects are passed by reference and can be compared using is and is not operators, which
tests for equality by looking at object identity (memory address)
Python modules and C-extensions can handle the encapsulation of C-pointers in Python objects
If Statements if (i<N)
statements;
else if (i>N)
statements;
else
statements;
if i<N:
statements
elif i>N:
statements
else:
statements
For Statements for (i=0; i < N; i++)
statements;
for i in range(N):
statements
While Statements while (i<N)
statements;
while i < N:
statements
Including files #include <stdio.h> import sys
Exception
Handling
None for arg in sys.argv[1:]:
try:
f = open(arg, 'r')
except IOError:
print 'cannot open', arg
else:
print arg, 'has', len(f.readlines()), 'lines‘
f.close()
Classes None class MyClass:
"A simple example class“
i = 12345
def f(self):
return 'hello world'
5. Tokens and Structure part III
Code Pattern C Python
Compound Data
Type Operations
None >>> a = ['spam', 'eggs', 100, 1234]
>>> a ['spam', 'eggs', 100, 1234]
>>> a[0]
'spam'
>>> a[3]
1234
>>> a[-2]
100
>>> a[1:-1]
['eggs', 100]
>>> a[:2] + ['bacon', 2*2]
['spam', 'eggs', 'bacon', 4]
>>> 3*a[:3] + ['Boe!']
['spam', 'eggs', 100, 'spam', 'eggs', 100, 'spam', 'eggs', 100, 'Boe!']
Multiple
Inheritance
None class DerivedClassName(Base1, Base2, Base3):
statements
Structs typedef struct
{
int x;
int array[100];
} Foo; /* note semi-colon here */
class Employee:
pass
john = Employee() # Create an empty employee record
# Fill the fields of the record
john.name = 'John Doe'
john.dept = 'computer lab‘
john.salary = 1000
Iterators None for element in [1, 2, 3]:
print element
The for loop calls iter() on element
Generators None def reverse(data):
for index in range(len(data)-1, -1, -1):
yield data[index]
>>> for char in reverse('golf'):
... print char
...
f
l
o
g
6. Script
# Need this to run console commands
import os
# Need this to send email
import smtplib
# Need this to process email
from email.MIMEText import MIMEText
# Need this for time
from time import strftime
# First, run the webchecker script and write results to file
os.system("webchecker.py -q http://169.237.48.10 > results.txt")
# Get local time
runtime = strftime('%a %d %b %Y %H:%M:%S')
# Open the file
fp = open("results.txt")
# Create message
msg = MIMEText(fp.read())
fp.close()
me = "Webnanny"
you = "AdamG@hrrm.ucdavis.edu"
msg['Subject'] = 'www.hr.ucdavis.edu link check %s' % runtime
msg['From'] = me
msg['To']= you
server = smtplib.SMTP('hrrm.ucdavis.edu')
server.set_debuglevel(1)
#server.connect()
server.sendmail(me, you, msg.as_string())
server.quit()
7. Procedural Program
"""Delete files older than AGING constant using os.path.walk"""
import sys, os, time
AGING = 172800 # Default 2 days
def lister(dummy, dirName, filesInDir):
print '[' + dirName + ']'
for fname in filesInDir:
path = os.path.join(dirName, fname)
if not os.path.isdir(path):
print path, time.ctime(os.stat(path).st_mtime), fileage(path),
prune(path)
purge(path)
def fileage(file):
curtime = time.time()
modtime = os.stat(file).st_mtime
age = curtime - modtime
return age
def prune(file):
if fileage(file) > AGING:
return ("T")
else:
return ("File should not be deleted")
def purge(file):
if prune(file) == "T":
os.remove(file)
if __name__ == '__main__':
os.path.walk(sys.argv[1], lister, None)
8. Object Oriented Program
class Employee:
def __init__(self, name, salary = 0):
self.name = name
self.salary = salary
def giveRaise(self, percent):
self.salary += self.salary * percent
def work(self):
print self.name, "does stuff"
def __repr__(self):
return "<Employee: name=%s, salary=%s>" % (self.name, self.salary)
class Chef(Employee):
def __init__(self, name):
Employee.__init__(self, name, 50000)
def work(self):
print self.name, "makes food"
class Server(Employee):
def __init__(self, name):
Employee.__init__(self, name, 40000)
def work(self):
print self.name, "interfaces with customers"
class PizzaRobot(Chef):
def __init__(self, name):
Chef.__init__(self,name)
def work(self):
print self.name, "makes pizza"
if __name__ == "__main__":
bob = PizzaRobot('bob')
print bob
bob.giveRaise(0.2)
print bob; print
for klass in Employee, Chef, Server, PizzaRobot:
obj = klass(klass.__name__)
obj.work()
9. Functional Programming
• Functions are first class objects. Everything done with "data" can be done with
functions (e.g. passing a function to another function).
• Recursion is used as the primary control structure. This allows the compiler to
determine the layout of program statements rather than the programmer (e.g., loops
don’t have to be “unrolled” for efficiency)
• There is a focus on LIST Processing (for example, the name Lisp). Lists are often used
with recursion on sub-lists as a substitute for loops.
• "Pure" functional languages eschew side-effects. This excludes the almost ubiquitous
pattern in imperative languages of assigning first one, then another value to the same
variable to track the program state.
• FP either discourages or outright disallows statements, and instead works with the
evaluation of expressions (in other words, functions plus arguments). In the pure case,
one program is one expression (plus supporting definitions).
• FP worries about what is to be computed rather than how it is to be computed.
• FP uses "higher order" functions (functions that operate on functions that operate on
functions) [1]
• Note: “Currying” allows functions of more than one variable to be converted to
composite functions of one variable, e.g. F(x,y,z) = g(x) ◦ h(y) ◦ i(z)
10. Functional Code
Code Pattern Procedural Functional
If Statements if i=1:
namenum(i)='one'
elif i=2:
namenum(i)='two'
else:
namenum(i)='other'
>>> pr = lambda s:s
>>> namenum = lambda x: (x==1 and pr("one"))
.... or (x==2 and pr("two"))
.... or (pr("other"))
>>> namenum(1)
'one'
>>> namenum(2)
'two'
>>> namenum(3)
'other'
For Statements for e in list: func(e) map(func, list)
While Statements while <cond>:
<pre-suite>
if <break_condition>:
break
else:
<suite>
def while_block():
<pre-suite>
if <break_condition>:
return 1
else:
<suite>
return 0
while_FP = lambda: (<cond> and while_block()) or while_FP()
Example Program xs = (1,2,3,4)
ys = (10,15,3,22)
bigmuls = []
# ...more stuff...
for x in xs:
for y in ys:
# ...more stuff...
if x*y > 25:
bigmuls.append((x,y))
# ...more stuff...
# ...more stuff...
print bigmuls
# No side-effects possible
bigmuls = lambda xs,ys: filter(lambda (x,y):x*y > 25, combine(xs,ys))
combine = lambda xs,ys: map(None, xs*len(ys), dupelms(ys,len(xs))) dupelms
= lambda lst,n: reduce(lambda s,t:s+t, map(lambda l,n=n: [l]*n, lst))
print bigmuls((1,2,3,4),(10,15,3,22)) #replace with list comprehension
List
Comprehensions
None print [(x,y) for x in (1,2,3,4) for y in (10,15,3,22) if x*y > 25]
11. Functional Code part II
Code Pattern C Python
QuickSort void q_sort( input_type a[], int left, int right )
{
int i, j;
input_type pivot;
if (left + CUTOFF <= right) {
/* CUTOFF should be 20 but example is 2 */
pivot = median3( a, left, right );
i = left; j = right-1; /* why? */
for (;;) {
while (a[++i] < pivot);
while (a[--j] > pivot);
if (i < j)
swap( &a[i], &a[j] );
else
break;
}
swap( &a[i], &a[right-1] ); /* why? */
q_sort( a, left, i-1 );
q_sort( a, i+1, right);
}
}
void quick_sort( input_type a[], int n ) {
q_sort( a, 1, n);
insertion_sort( a, n );
/* n<=20: insertion is better, use CUTOFF */ }
def qsort(L):
if L == []: return []
return qsort([x for x in L[1:] if x< L[0] ]) + L[0:1] +
qsort([x for x in L[1:] if x>=L[0] ])
12. References
1. ActivePython from ActiveState
– http://www.activestate.com/Products/ActivePython/
1. Charming Python: Functional programming in Python, Part 1
– http://www-106.ibm.com/developerworks/library/l-prog.html
1. Currying: From Wikipedia
– http://en.wikipedia.org/wiki/Currying
1. Enhanced Python Distribution from EnThought
– http://www.enthought.com/python/
1. MatPlotLib: SourceForge
– http://matplotlib.sourceforge.net/
1. Numarray: Space Telescope Science Institute
– http://www.stsci.edu/resources/software_hardware/numarray
1. Python - Object/Type Structures
– http://wiki.cs.uiuc.edu/cs427/Python+-+Object%2FType+Structures
1. Python Software Foundation
1. http://www.python.org/
1. Python Programming Language: From Wikipedia
– http://en.wikipedia.org/wiki/Python_programming_language
Editor's Notes
Dynamically typed – variables typed on the fly, can change
SAX = Simple API for XML, used for speedy reading, not good for writes
DOM = Document Object Model, memory-resident tree
XPath = Selecting subset of nodes in a DOM tree
Tuples (), immutable
Lists [], mutable,
Dictionaries {}, key:value,
Enumerator goes through iterator
Iterator used to step through sequence
Lexical scoping – defaults to scope of nearest enclosing function/class block
First class – Can be assigned or passed to like variables, i.e. functions of functions
Generator is “resumable function”
List Comprehensions
range(N) is a function that generates 0 to N-1
sys.argv[1:] is a “slice” that reads arguments 1, 2, …, N
Can also use try … finally to ensure an action is taken and raise to raise an exception
In the class, MyClass.i refers to an integer attribute and MyClass.f refers to a method attribute
Iter() defines next method and raises StopIteration Exception when completed
Generators remember values when next() is called on the iterator
Local variables and execution state are saved between calls
Generators automatically create __iter__() and next()
Map(func, list) applies func to every element in list
apply(function, args[, keywords]) equivalent to function(*args, **keywords)
filter(function, list) equivalent to [item for item in list if function(item)] if function is not None and [item for item in list if item] if function is None.
Map(func, list) applies func to every element in list
apply(function, args[, keywords]) equivalent to function(*args, **keywords)
filter(function, list) equivalent to [item for item in list if function(item)] if function is not None and [item for item in list if item] if function is None.