万本电子书0元读

万本电子书0元读

顶部广告

Functional Python Programming电子书

售       价:¥

7人正在读 | 0人评论 9.8

作       者:Steven F. Lott

出  版  社:Packt Publishing

出版时间:2018-04-13

字       数:60.1万

所属分类: 进口书 > 外文原版书 > 电脑/网络

温馨提示:数字商品不支持退换货,不提供源文件,不支持导出打印

为你推荐

  • 读书简介
  • 目录
  • 累计评论(0条)
  • 读书简介
  • 目录
  • 累计评论(0条)
Create succinct and expressive implementations with functional programming in Python About This Book ? Learn how to choose between imperative and functional approaches based on expressiveness, clarity, and performance ? Get familiar with complex concepts such as monads, concurrency, and immutability ? Apply functional Python to common Exploratory Data Analysis (EDA) programming problems Who This Book Is For This book is for Python developers who would like to perform Functional programming with Python. Python Programming knowledge is assumed. What You Will Learn ? Use Python's generator functions and generator expressions to work with collections in a non-strict (or lazy) manner ? Utilize Python library modules including itertools, functools, multiprocessing, and concurrent features to ensure efficient functional programs ? Use Python strings with object-oriented suffix notation and prefix notation ? Avoid stateful classes with families of tuples ? Design and implement decorators to create composite functions ? Use functions such as max(), min(), map(), filter(), and sorted() ? Write higher-order functions In Detail If you’re a Python developer who wants to discover how to take the power of functional programming (FP) and bring it into your own programs, then this book is essential for you, even if you know next to nothing about the paradigm. Starting with a general overview of functional concepts, you’ll explore common functional features such as first-class and higher-order functions, pure functions, and more. You’ll see how these are accomplished in Python 3.6 to give you the core foundations you’ll build upon. After that, you’ll discover common functional optimizations for Python to help your apps reach even higher speeds. You’ll learn FP concepts such as lazy evaluation using Python’s generator functions and expressions. Moving forward, you’ll learn to design and implement decorators to create composite functions. You'll also explore data preparation techniques and data exploration in depth, and see how the Python standard library fits the functional programming model. Finally, to top off your journey into the world of functional Python, you’ll at look at the PyMonad project and some larger examples to put everything into perspective. Style and approach This book provides a general overview of functional concepts and then delves deeper into the functional features, showing you how the Python standard library fits the functional programming model. It also demonstrates how to implement common functional programming design patterns and techniques in Python.
目录展开

Title Page

Copyright and Credits

Functional Python Programming Second Edition

Packt Upsell

Why subscribe?

PacktPub.com

Contributors

About the author

About the reviewer

Packt is searching for authors like you

Preface

Who this book is for

What this book covers

To get the most out of this book

Download the example code files

Conventions used

Get in touch

Reviews

Understanding 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

Introducing Essential Functional Concepts

First-class functions

Pure functions

Higher-order functions

Immutable data

Strict and non-strict evaluation

Recursion instead of an explicit loop state

Functional type systems

Familiar territory

Learning some advanced concepts

Summary

Functions, Iterators, and Generators

Writing pure functions

Functions as first-class objects

Using strings

Using tuples and named tuples

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

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

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

Review of some design patterns

Summary

Recursions and Reductions

Simple numerical recursions

Implementing tail-call optimization

Leaving recursion in place

Handling difficult tail-call optimization

Processing collections through recursion

Tail-call optimization for collections

Reductions and folding a collection from many items to one

Group-by reduction from many items 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

Additional Tuple Techniques

Using tuples to collect data

Using named tuples to collect data

Building named tuples 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 Spearman rank-order correlation

Polymorphism and type-pattern matching

Summary

The Itertools Module

Working with the infinite iterators

Counting with count()

Counting with float arguments

Re-iterating 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

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

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 the reduce() function

Combining map() and reduce()

Using the reduce() and partial() functions

Using the map() and reduce() functions to sanitize raw data

Using the groupby() and reduce() functions

Summary

Decorator Design Techniques

Decorators as higher-order functions

Using the functools update_wrapper() functions

Cross-cutting concerns

Composite design

Preprocessing bad data

Adding a parameter to a decorator

Implementing more complex decorators

Complex design considerations

Summary

The Multiprocessing and Threading Modules

Functional programming and concurrency

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 additional fields of an Access object

Filtering the access details

Analyzing the access details

The complete analysis process

Using a multiprocessing pool for concurrent processing

Using apply() to make a single request

Using the map_async(), starmap_async(), and apply_async() functions

More complex multiprocessing architectures

Using the concurrent.futures module

Using concurrent.futures thread pools

Using the threading and queue modules

Designing concurrent processing

Summary

Conditional Expressions and the Operator Module

Evaluating conditional expressions

Exploiting non-strict dictionary rules

Filtering true conditional expressions

Finding a matching pattern

Using the operator module instead of lambdas

Getting named attributes when using higher-order functions

Starmapping with operators

Reducing with operator module functions

Summary

The PyMonad Library

Downloading and installing

Functional composition and currying

Using curried higher-order functions

Currying the hard way

Functional composition and the PyMonad * operator

Functors and applicative functors

Using the lazy List() functor

Monad bind() function and the >> operator

Implementing simulation with monads

Additional PyMonad features

Summary

A Functional Approach to Web Services

The HTTP request-response model

Injecting state through cookies

Considering a server with a functional design

Looking more deeply into the functional view

Nesting the services

The WSGI standard

Throwing exceptions during WSGI processing

Pragmatic WSGI applications

Defining web services as functions

Creating the WSGI application

Getting raw data

Applying a filter

Serializing the results

Serializing data into JSON or CSV formats

Serializing data into XML

Serializing data into HTML

Tracking usage

Summary

Optimizations and Improvements

Memoization and caching

Specializing memoization

Tail recursion optimizations

Optimizing storage

Optimizing accuracy

Reducing accuracy based on audience requirements

Case study–making a chi-squared decision

Filtering and reducing the raw data with a Counter object

Reading summarized data

Computing sums with a Counter object

Computing probabilities from Counter objects

Computing expected values and displaying a contingency table

Computing the chi-squared value

Computing the chi-squared threshold

Computing the incomplete gamma function

Computing the complete gamma function

Computing the odds of a distribution being random

Functional programming design patterns

Summary

Other Books You May Enjoy

Leave a review - let other readers know what you think

累计评论(0条) 0个书友正在讨论这本书 发表评论

发表评论

发表评论,分享你的想法吧!

买过这本书的人还买过

读了这本书的人还在读

回顶部