Intermediate Python 9781501521744

This book provides you with relevant information about using intermediate Python 3.x for a variety of topics, such as co

204 9 7MB

English Pages 196 Year 2023

Report DMCA / Copyright


Intermediate Python

Table of contents :
Title Page
Copyright Page
Chapter 1: Data Structures in Python
Working with Lists
Lists and Basic Operations
Reversing and Sorting a List
Lists and Arithmetic Operations
Lists and Filter-Related Operations
Calculating Squares and Cubes in Lists
Sorting Lists of Numbers and Strings
Concatenating a List of Words
The Python range() Function
Counting Digits and Uppercase and Lowercase Letters
Lists and the append() Function
Working with Lists and the split() Function
Counting Words in a List
Iterating Through Pairs of Lists
List Slices
Other List-Related Functions
Working with Vectors
Working with Matrices
Tuples (Immutable Lists)
Creating a Dictionary
Displaying the Contents of a Dictionary
Checking for Keys in a Dictionary
Deleting Keys from a Dictionary
Iterating Through a Dictionary
Interpolating Data from a Dictionary
Dictionary Functions and Methods
Ordered Dictionaries
Sorting Dictionaries
Dictionary Formatting
Multiple Dictionaries
Other Sequence Types
Mutable and Immutable Types
Packing/Unpacking Sequences
Automatic Packing (Direct Assignment)
Unpacking Return Values of Functions
Swapping Pairs of Values
Iterating Sequences in Loops
Serialize and Deserialize Data
Modules versus Packages
User-Defined Functions
Functions versus Methods
Functions with Generic Arguments
Functions that Specify *args
Functions that Specify **kwargs
Chapter 2: Comprehensions, Iterators, and Generators
Lambda Expressions
Magic Methods (Dunders)
The Iterator Protocol
The iter() Function and __iter__() Method
Dictionaries and Iterators
Examples of Iterators
Range versus a List
Functional Programming: the map() Function
Functional Programming: the filter() Function
Combining the filter() and map() Functions
The reduce() Function
What is a Pipe?
Working with Generators
The Yield Keyword
Generators and Comprehensions
A Generator Without a Loop
Miscellaneous Examples of Generators
Generate Squares of Numbers
Generate an Infinite List of Integers
Find Prime Numbers
Examples of Decorators
Importing Custom Modules
Compiled Modules
Classes, Functions, and Methods
Function Annotations
Function Annotations (1)
Function Annotations (2)
Function Annotations (3)
Function Annotations (4)
Function Annotations (5)
Chapter 3: Regular Expressions
What are Regular Expressions?
Character Sets
Working with “^” and “\”
Character Classes
Matching Character Classes with the re Module
Compilation Flags
Using the re.match() Method
Options for the re.match() Method
Matching Character Classes with the Method
Matching Character Classes with the findAll() Method
Finding Capitalized Words in a String
Additional Matching Functions for Regular Expressions
Grouping with Character Classes in Regular Expressions
Using Character Classes in Regular Expressions
Matching Strings with Multiple Consecutive Digits
Reversing Words in Strings
Modifying Text Strings with the re Module
Splitting Text Strings with the re.split() Method
Splitting Text Strings Using Digits and Delimiters
Substituting Text Strings with the re.sub() Method
Matching the Beginning and End of Text Strings
Compound Regular Expressions
Counting Character Types in a String
Regular Expressions and Grouping
Simple String Matches
Additional Topics for Regular Expressions
Chapter 4: Custom Classes
Accessibility Conventions
Creating Custom Classes
Instance Variables versus Class Variables
Examples of Custom Classes
A Custom Class with an Iterator
A Custom Class with an Invalid Iterator
Construction and Initialization of Objects
Accessors and Mutators versus @property
The Methods __str__() and __repr__()
Creating a Point3D Custom Class
Comparing Two Instances of a Custom Class
The Methods __add__() and __radd__()
Creating an Employee Custom Class
Working with a List of Employees
A Python Iterable Class
Working with Linked Lists
Custom Classes and Linked Lists
Custom Classes and Dictionaries
Custom Classes and Priority Queues
The Base Classes of a Given Class
Single Inheritance
An Example of Inheritance
Inheritance and Overriding Methods
Multiple Inheritance
The abc Module
Chapter 5: Queues and Stacks
What is a Queue?
Types of Queues
Creating a Queue Using a Python List
Creating a Rolling Queue
Creating a Shifting Queue using a List
Creating an Iterable Queue
What is a Stack?
Use Cases for Stacks
Operations with Stacks
Working with Stacks
Creating an Iterable Stack
Task: Reverse and Print Stack Values
Task: Display the Min and Max Stack Values
Creating Two Stacks Using an Array
Task: Reverse a String Using a Stack
Task: Balanced Parentheses (1)
Task: Balanced Parentheses (2)
Task: Tokenize Arithmetic Expressions
Task: Evaluate Arithmetic Expressions
Infix, Prefix, and Postfix Notations
Chapter 6: Recursion and Combinatorics
What is Recursion?
Arithmetic Series
Calculating an Arithmetic Series (Iterative)
Calculating an Arithmetic Series (Recursive)
Calculating a Partial Arithmetic Series
Geometric Series
Calculating a Geometric Series (Iterative)
Calculating a Geometric Series (Recursive)
Factorial Values
Calculating Factorial Values (Iterative)
Calculating Factorial Values (Recursive)
Calculating Factorial Values (Tail Recursion)
Fibonacci Numbers
Calculating Fibonacci Numbers (Recursive)
Calculating Fibonacci Numbers (Iterative)
Task: Reverse a String via Recursion
Task: Check for Balanced Parentheses (Iterative)
Task: Calculate the Number of Digits
Task: Determine if a Positive Integer is Prime (Iterative)
Task: Find the Prime Factorization of a Positive Integer (Iterative)
Task: Goldbach’s Conjecture
Task: Calculate the GCD (Greatest Common Divisor)
Task: Calculate the LCM
What is Combinatorics?
Working with Permutations
Working with Combinations
Task: Calculate the Sum of Binomial Coefficients
The Number of Subsets of a Finite Set
Task: Subsets Containing a Value Larger than k

Polecaj historie