Skip to content

jeremyfromearth/one-a-day-one-liners-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

82 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

One a Day One Liners with Python

Everyday I add a new Python One Liner to my Medium blog. Sometimes they are deceptively simple but merit a deep dive and others just demonstrate basic language features. The motivation for this project is to keep myself learning new things about the Python language everyday and to encourage a wider dialog and collaboration with others in the Python community. Feel free to leave comments on the blog or better yet clone the repo and contribute to the project.

One Liner Criteria

This project is just for fun and doesn't seek to enforce any hard and fast rules, but it does make sense to provide a basic description of what is meant by the term "One Liner"

Note: These guidelines are completely subject to change!

  1. All of the One Liners are going to be written with Python 3.6 and up.
  2. One Liner should not greatly exceed the line length as described in the PEP8, which is currently 72 characters. Update: I have not adhered to this at all!
  3. import statements don't count as lines.
  4. One or two variables declared before a One Liner don't count as lines.
  5. A One Liner should not use third party libraries. There is plenty to explore in the standard library!

Table of Contents

January 2023

  • 01 - Generate a random eight character id! 🥇
  • 02 - Divide and floor with double slash, simple and effective 👍🏻
  • 03 - Find the nclosest matches to a given string, using difflib 🧐
  • 04 - Spin up a web server from the command line… 🕸
  • 05 - k-permutations of n 🧮
  • 06 - Memoize a function 🐘
  • 07 - Tokenize text 📚
  • 08 - Generate n-grams ✂️
  • 09 - Create a Bag of Words model with the Counter 🔢
  • 10 - Redact a top secret document 🕵🏻‍♂️
  • 11 - Remove all that pesky punctuation with str.translate 🔤
  • 12 - Remove stop words 🫣
  • 13 - Count most common phrases of length n 💯
  • 14 - Find occurrences of terms or phrases 🔎
  • 15 - Create an identity matrix 🪪
  • 16 - Find the transpose a square matrix 🙃
  • 17 - Multiply two matrices 🅰️🅱️
  • 18 - Partition a matrix into a sub-matrix 🍕
  • 19 - Compute the direct sum of two matrices ⊕
  • 20 - Calculate the cosine similarity of two vectors ← ↑ →
  • 21 - Calculate the Frobenius norm of a matrix √
  • 22 - Apply a function over each line of a file 📄
  • 23 - Create timed rotating logs 🪵
  • 24 - Make a JSON file human readable 🤖 → 💁
  • 25 - Convert a CSV file into a JSON file 🚣🏻‍♀️ → 📦
  • 26 - Search all files in a directory for a term or phrase 🔍
  • 27 - Auto-detect the delimiter of a CSV file and parse it 🐶
  • 28 - Remove all files of a specific type from the current dir 🗑️
  • 29 - Determine if a point is within a plane 👉🏻 ✈️
  • 30 - Generate geometry for an n-sided regular polygon ▲ ⬣
  • 31 - Find the centroid of a regular 2D polygon ⏺️

Feb 2023

  • 01 - Find the intersection of two rectangles 🚦∩
  • 02 - Determine if two rectangles overlap ⧉
  • 03 - Scale and rotation invariant triangle similarity test 📐
  • 04 - Generate a grid of rectangles 🟥 🟧 🟨
  • 05 - Create a Poisson distribution 🔔
  • 06 - Generate a variable length pseudo random key 🗝️
  • 07 - Create a year of mock weather data ❄️🌿☀️🍂📈
  • 08 - Never make a choice on your own again, with a Magic 8 Ball One Liner 🎱
  • 09 - Calculate the probability of rolling 8, twice in 10 rolls of a 20 sided die 🎲
  • 10 - Let’s make some noise 🎧
  • 11 - A random walk in a 2D plane with a One Liner 🤔 🚶🏻
  • 12 - Compute the powers of 2 up to N with starmap ✨ 🗺️
  • 13 - Run a batch process using iter and islice 🍪
  • 14 - Calculate the moving average for stock data 📈
  • 15 - Unleash chaos into Universe by computing values of the Logistic Map 💥
  • 16 - Group items in tabular data by column 💿
  • 17 - Filter out rows of data based on a character range of a given column 🥡
  • 18 - Easily generate all r permutations of a given list of items 🪄
  • 19 - Compute an arithmetic series 🧮
  • 20 - Find the partial sum of an exponential sequence 🤯
  • 21 - Compute a range of digits from the Fibonacci Sequence 2️⃣ 3️⃣ 5️⃣'

Resources

About

Every day I add a new Python One Liner

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages