Book description
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 learnhow 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.
Table of contents
- Cover Page
- Title Page
- Copyright Page
- Dedication
- About the Author
- About the Technical Reviewer
- Brief Contents
- Contents in Detail
- Acknowledgments
- Introduction
- 1 Python Refresher
-
2 Python Tricks
- Using List Comprehension to Find Top Earners
- Using List Comprehension to Find Words with High Information Value
- Reading a File
- Using Lambda and Map Functions
- Using Slicing to Extract Matching Substring Environments
- Combining List Comprehension and Slicing
- Using Slice Assignment to Correct Corrupted Lists
- Analyzing Cardiac Health Data with List Concatenation
- Using Generator Expressions to Find Companies That Pay Below Minimum Wage
- Formatting Databases with the zip() Function
- Summary
-
3 Data Science
- Basic Two-Dimensional Array Arithmetic
- Working with NumPy Arrays: Slicing, Broadcasting, and Array Types
- Conditional Array Search, Filtering, and Broadcasting to Detect Outliers
- Boolean Indexing to Filter Two-Dimensional Arrays
- Broadcasting, Slice Assignment, and Reshaping to Clean Every i-th Array Element
- When to Use the sort() Function and When to Use the argsort() Function in NumPy
- How to Use Lambda Functions and Boolean Indexing to Filter Arrays
- How to Create Advanced Array Filters with Statistics, Math, and Logic
- Simple Association Analysis: People Who Bought X Also Bought Y
- Intermediate Association Analysis to Find Bestseller Bundles
- Summary
-
4 Machine Learning
- The Basics of Supervised Machine Learning
- Linear Regression
- Logistic Regression in One Line
- K-Means Clustering in One Line
- K-Nearest Neighbors in One Line
- Neural Network Analysis in One Line
- Decision-Tree Learning in One Line
- Get Row with Minimal Variance in One Line
- Basic Statistics in One Line
- Classification with Support-Vector Machines in One Line
- Classification with Random Forests in One Line
- Summary
-
5 Regular Expressions
- Finding Basic Textual Patterns in Strings
- Writing Your First Web Scraper with Regular Expressions
- Analyzing Hyperlinks of HTML Documents
- Extracting Dollars from a String
- Finding Nonsecure HTTP URLs
- Validating the Time Format of User Input, Part 1
- Validating Time Format of User Input, Part 2
- Duplicate Detection in Strings
- Detecting Word Repetitions
- Modifying Regex Patterns in a Multiline String
- Summary
-
6 Algorithms
- Finding Anagrams with Lambda Functions and Sorting
- Finding Palindromes with Lambda Functions and Negative Slicing
- Counting Permutations with Recursive Factorial Functions
- Finding the Levenshtein Distance
- Calculating the Powerset by Using Functional Programming
- Caesar’s Cipher Encryption Using Advanced Indexing and List Comprehension
- Finding Prime Numbers with the Sieve of Eratosthenes
- Calculating the Fibonacci Series with the reduce() Function
- A Recursive Binary Search Algorithm
- A Recursive Quicksort Algorithm
- Summary
- Afterword
- Index
Product information
- Title: Python One-Liners
- Author(s):
- Release date: April 2020
- Publisher(s): No Starch Press
- ISBN: 9781718500501
You might also like
book
Object-Oriented Python
Object-Oriented Python (OOP) is a paradigm that combines data and code into cohesive units, allowing you …
book
Python Workout
The only way to master a skill is to practice. In Python Workout, author Reuven M. …
video
Python Programming Language
6+ Hours of Video Instruction Python Programming Language LiveLessons provides developers with a guided tour of …
book
Data Structures and Algorithms in Python
Based on the authors' market leading data structures books in Java and C++, this textbook offers …