Contents in Detail – Python One-Liners

CONTENTS IN DETAIL

ACKNOWLEDGMENTS

INTRODUCTION

Python One-Liner Example

A Note on Readability

Who Is This Book For?

What Will You Learn?

Online Resources

1
PYTHON REFRESHER

Basic Data Structures

Numerical Data Types and Structures

Booleans

Strings

The Keyword None

Container Data Structures

Lists

Stacks

Sets

Dictionaries

Membership

List and Set Comprehension

Control Flow

if, else, and elif

Loops

Functions

Lambdas

Summary

2
PYTHON TRICKS

Using List Comprehension to Find Top Earners

The Basics

The Code

How It Works

Using List Comprehension to Find Words with High Information Value

The Basics

The Code

How It Works

Reading a File

The Basics

The Code

How It Works

Using Lambda and Map Functions

The Basics

The Code

How It Works

Using Slicing to Extract Matching Substring Environments

The Basics

The Code

How It Works

Combining List Comprehension and Slicing

The Basics

The Code

How It Works

Using Slice Assignment to Correct Corrupted Lists

The Basics

The Code

How It Works

Analyzing Cardiac Health Data with List Concatenation

The Basics

The Code

How It Works

Using Generator Expressions to Find Companies That Pay Below Minimum Wage

The Basics

The Code

How It Works

Formatting Databases with the zip() Function

The Basics

The Code

How It Works

Summary

3
DATA SCIENCE

Basic Two-Dimensional Array Arithmetic

The Basics

The Code

How It Works

Working with NumPy Arrays: Slicing, Broadcasting, and Array Types

The Basics

The Code

How It Works

Conditional Array Search, Filtering, and Broadcasting to Detect Outliers

The Basics

The Code

How It Works

Boolean Indexing to Filter Two-Dimensional Arrays

The Basics

The Code

How It Works

Broadcasting, Slice Assignment, and Reshaping to Clean Every i-th Array Element

The Basics

The Code

How It Works

When to Use the sort() Function and When to Use the argsort() Function in NumPy

The Basics

The Code

How It Works

How to Use Lambda Functions and Boolean Indexing to Filter Arrays

The Basics

The Code

How It Works

How to Create Advanced Array Filters with Statistics, Math, and Logic

The Basics

The Code

How It Works

Simple Association Analysis: People Who Bought X Also Bought Y

The Basics

The Code

How It Works

Intermediate Association Analysis to Find Bestseller Bundles

The Basics

The Code

How It Works

Summary

4
MACHINE LEARNING

The Basics of Supervised Machine Learning

Training Phase

Inference Phase

Linear Regression

The Basics

The Code

How It Works

Logistic Regression in One Line

The Basics

The Code

How It Works

K-Means Clustering in One Line

The Basics

The Code

How It Works

K-Nearest Neighbors in One Line

The Basics

The Code

How It Works

Neural Network Analysis in One Line

The Basics

The Code

How It Works

Decision-Tree Learning in One Line

The Basics

The Code

How It Works

Get Row with Minimal Variance in One Line

The Basics

The Code

How It Works

Basic Statistics in One Line

The Basics

The Code

How It Works

Classification with Support-Vector Machines in One Line

The Basics

The Code

How It Works

Classification with Random Forests in One Line

The Basics

The Code

How It Works

Summary

5
REGULAR EXPRESSIONS

Finding Basic Textual Patterns in Strings

The Basics

The Code

How It Works

Writing Your First Web Scraper with Regular Expressions

The Basics

The Code

How It Works

Analyzing Hyperlinks of HTML Documents

The Basics

The Code

How It Works

Extracting Dollars from a String

The Basics

The Code

How It Works

Finding Nonsecure HTTP URLs

The Basics

The Code

How It Works

Validating the Time Format of User Input, Part 1

The Basics

The Code

How It Works

Validating Time Format of User Input, Part 2

The Basics

The Code

How It Works

Duplicate Detection in Strings

The Basics

The Code

How It Works

Detecting Word Repetitions

The Basics

The Code

How It Works

Modifying Regex Patterns in a Multiline String

The Basics

The Code

How It Works

Summary

6
ALGORITHMS

Finding Anagrams with Lambda Functions and Sorting

The Basics

The Code

How It Works

Finding Palindromes with Lambda Functions and Negative Slicing

The Basics

The Code

How It Works

Counting Permutations with Recursive Factorial Functions

The Basics

The Code

How It Works

Finding the Levenshtein Distance

The Basics

The Code

How It Works

Calculating the Powerset by Using Functional Programming

The Basics

The Code

How It Works

Caesar’s Cipher Encryption Using Advanced Indexing and List Comprehension

The Basics

The Code

How It Works

Finding Prime Numbers with the Sieve of Eratosthenes

The Basics

The Code

How It Works

Calculating the Fibonacci Series with the reduce() Function

The Basics

The Code

How It Works

A Recursive Binary Search Algorithm

The Basics

The Code

How It Works

A Recursive Quicksort Algorithm

The Basics

The Code

How It Works

Summary

AFTERWORD

INDEX