Functional Python Programming
eBook - ePub

Functional Python Programming

Steven Lott

Condividi libro
  1. 360 pagine
  2. English
  3. ePUB (disponibile sull'app)
  4. Disponibile su iOS e Android
eBook - ePub

Functional Python Programming

Steven Lott

Dettagli del libro
Anteprima del libro
Indice dei contenuti
Citazioni

Domande frequenti

Come faccio ad annullare l'abbonamento?
È semplicissimo: basta accedere alla sezione Account nelle Impostazioni e cliccare su "Annulla abbonamento". Dopo la cancellazione, l'abbonamento rimarrà attivo per il periodo rimanente già pagato. Per maggiori informazioni, clicca qui
È possibile scaricare libri? Se sì, come?
Al momento è possibile scaricare tramite l'app tutti i nostri libri ePub mobile-friendly. Anche la maggior parte dei nostri PDF è scaricabile e stiamo lavorando per rendere disponibile quanto prima il download di tutti gli altri file. Per maggiori informazioni, clicca qui
Che differenza c'è tra i piani?
Entrambi i piani ti danno accesso illimitato alla libreria e a tutte le funzionalità di Perlego. Le uniche differenze sono il prezzo e il periodo di abbonamento: con il piano annuale risparmierai circa il 30% rispetto a 12 rate con quello mensile.
Cos'è Perlego?
Perlego è un servizio di abbonamento a testi accademici, che ti permette di accedere a un'intera libreria online a un prezzo inferiore rispetto a quello che pagheresti per acquistare un singolo libro al mese. Con oltre 1 milione di testi suddivisi in più di 1.000 categorie, troverai sicuramente ciò che fa per te! Per maggiori informazioni, clicca qui.
Perlego supporta la sintesi vocale?
Cerca l'icona Sintesi vocale nel prossimo libro che leggerai per verificare se è possibile riprodurre l'audio. Questo strumento permette di leggere il testo a voce alta, evidenziandolo man mano che la lettura procede. Puoi aumentare o diminuire la velocità della sintesi vocale, oppure sospendere la riproduzione. Per maggiori informazioni, clicca qui.
Functional Python Programming è disponibile online in formato PDF/ePub?
Sì, puoi accedere a Functional Python Programming di Steven Lott in formato PDF e/o ePub, così come ad altri libri molto apprezzati nelle sezioni relative a Informatique e Programmation Open Source. Scopri oltre 1 milione di libri disponibili nel nostro catalogo.

Informazioni

Anno
2015
ISBN
9781784396992

Functional Python Programming


Table of Contents

Functional Python Programming
Credits
About the Author
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why subscribe?
Free access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. Introducing Functional Programming
Identifying a paradigm
Subdividing the procedural paradigm
Using the functional paradigm
Using a functional hybrid
Looking at object creation
The stack of turtles
A classic example of functional programming
Exploratory Data Analysis
Summary
2. Introducing Some Functional Features
First-class functions
Pure functions
Higher-order functions
Immutable data
Strict and non-strict evaluation
Recursion instead of a explicit loop state
Functional type systems
Familiar territory
Saving some advanced concepts
Summary
3. Functions, Iterators, and Generators
Writing pure functions
Functions as first-class objects
Using strings
Using tuples and namedtuples
Using generator expressions
Exploring the limitations of generators
Combining generator expressions
Cleaning raw data with generator functions
Using lists, dicts, and sets
Using stateful mappings
Using the bisect module to create a mapping
Using stateful sets
Summary
4. Working with Collections
An overview of function varieties
Working with iterables
Parsing an XML file
Parsing a file at a higher level
Pairing up items from a sequence
Using the iter() function explicitly
Extending a simple loop
Applying generator expressions to scalar functions
Using any() and all() as reductions
Using len() and sum()
Using sums and counts for statistics
Using zip() to structure and flatten sequences
Unzipping a zipped sequence
Flattening sequences
Structuring flat sequences
Structuring flat sequences—an alternative approach
Using reversed() to change the order
Using enumerate() to include a sequence number
Summary
5. Higher-order Functions
Using max() and min() to find extrema
Using Python lambda forms
Lambdas and the lambda calculus
Using the map() function to apply a function to a collection
Working with lambda forms and map()
Using map() with multiple sequences
Using the filter() function to pass or reject data
Using filter() to identify outliers
The iter() function with a sentinel value
Using sorted() to put data in order
Writing higher-order functions
Writing higher-order mappings and filters
Unwrapping data while mapping
Wrapping additional data while mapping
Flattening data while mapping
Structuring data while filtering
Writing generator functions
Building higher-order functions with Callables
Assuring good functional design
Looking at some of the design patterns
Summary
6. Recursions and Reductions
Simple numerical recursions
Implementing tail-call optimization
Leaving recursion in place
Handling difficult tail-call optimization
Processing collections via recursion
Tail-call optimization for collections
Reductions and folding – from many to one
Group-by reductions – from many to fewer
Building a mapping with Counter
Building a mapping by sorting
Grouping or partitioning data by key values
Writing more general group-by reductions
Writing higher-order reductions
Writing file parsers
Parsing CSV files
Parsing plain text files with headers
Summary
7. Additional Tuple Techniques
Using an immutable namedtuple as a record
Building namedtuples with functional constructors
Avoiding stateful classes by using families of tuples
Assigning statistical ranks
Wrapping instead of state changing
Rewrapping instead of state changing
Computing the Spearman rank-order correlation
Polymorphism and Pythonic pattern matching
Summary
8. The Itertools Module
Working with the infinite iterators
Counting with count()
Reiterating a cycle with cycle()
Repeating a single value with repeat()
Using the finite iterators
Assigning numbers with enumerate()
Running totals with accumulate()
Combining iterators with chain()
Partitioning an iterator with groupby()
Merging iterables with zip_longest() and zip()
Filtering with compress()
Picking subsets with islice()
Stateful filtering with dropwhile() and takewhile()
Two approaches to filtering with filterfalse() and filter()
Applying a function to data via starmap() and map()
Cloning iterators with tee()
The itertools recipes
Summary
9. More Itertools Techniques
Enumerating the Cartesian product
Reducing a product
Computing distances
Getting all pixels and all colors
Performance analysis
Rearranging the problem
Combining two transformations
Permuting a collection of values
Generating all combinations
Recipes
Summary
10. The Functools Module
Function tools
Memoizing previous results with lru_cache
Defining classes with total ordering
Defining number classes
Applying partial arguments with partial()
Reducing sets of data with reduce()
Combining map() and reduce()
Using reduce() and partial()
Using map() and reduce() to sanitize raw data
Using groupby() and reduce()
Summary
11. Decorator Design Techniques
Decorators as higher-order functions
Using functool's update_wrapper() functions
Cross-cutting concerns
Composite design
Preprocessing bad data
Adding a parameter to a decorator
Implementing more complex descriptors
Recognizing design limitations
Summary
12. The Multiprocessing and Threading Modules
What concurrency really means
The boundary conditions
Sharing resources with process or threads
Where benefits will accrue
Using multiprocessing pools and tasks
Processing many large files
Parsing log files – gathering the rows
Parsing log lines into namedtuples
Parsing additi...

Indice dei contenuti