Python programmers will improve their computer science skills with these useful one-liners.
Python One-Liners will teach you how to read and write "one-liners": concise statements of useful functionality packed into a single line of code. You'll learn how to systematically unpack and understand any line of Python code, and write eloquent, powerfully compressed Python like an expert.
The book's five chapters cover tips and tricks, regular expressions, machine learning, core data science topics, and useful algorithms. Detailed explanations of one-liners introduce key computer science concepts and boost your coding and analytical skills. You'll learn about advanced Python features such as list comprehension, slicing, lambda functions, regular expressions, map and reduce functions, and slice assignments. You'll also learn how to:
• Leverage data structures to solve real-world problems, like using Boolean indexing to find cities with above-average pollution
• Use NumPy basics such as array, shape, axis, type, broadcasting, advanced indexing, slicing, sorting, searching, aggregating, and statistics
• Calculate basic statistics of multidimensional data arrays and the K-Means algorithms for unsupervised learning
• Create more advanced regular expressions using grouping and named groups, negative lookaheads, escaped characters, whitespaces, character sets (and negative characters sets), and greedy/nongreedy operators
• Understand a wide range of computer science topics, including anagrams, palindromes, supersets, permutations, factorials, prime numbers, Fibonacci numbers, obfuscation, searching, and algorithmic sorting
By the end of the book, you'll know how to write Python at its most refined, and create concise, beautiful pieces of "Python art" in merely a single line.
Author(s): Christian Mayer
Edition: 1
Publisher: No Starch Press
Year: 2020
Language: English
Commentary: Vector PDF
Pages: 216
City: San Francisco, CA
Tags: Machine Learning; Algorithms; To Read; Decision Trees; Data Science; Programming; Python; Classification; Support Vector Machines; Statistics; Lambda Functions; Linear Regression; Logistic Regression; NumPy; Random Forest; Regular Expressions; Recursive Algorithms; Elementary; Python One-Liners
Brief Contents
Contents in Detail
Acknowledgments
Introduction
Python One-Liner Example
A Note on Readability
Who Is This Book For?
What Will You Learn?
Online Resources
Chapter 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
Chapter 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
Chapter 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
Chapter 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
Chapter 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
Chapter 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