Python in Plain English

New Python content every day. Follow to join our 3.5M+ monthly readers.

Follow publication

One a Day One Liners with Python — Week 2

Jeremy Brown
Python in Plain English
5 min readJan 7, 2023

Welcome Back!

Jan 14, 2023

terms = ['species of a genus', 'differs', 'mutatation']
result = [(term, i) for term in terms for i in range(len(text)) if text.startswith(term, i)]

Jan 13, 2023

n = 6
top_n = 50
phrases = Counter([' '.join(tokens[i:i+n]) for i in range(0, len(tokens))]).most_common(top_n)
1: however much they may differ from each other - (4 times)
2: succession of the same types within the same - (4 times)
3: the nature of the organism and of the - (3 times)
4: where many species of a genus have been - (3 times)
5: on the view that species are only strongly - (3 times)
6: the view that species are only strongly marked - (3 times)
7: view that species are only strongly marked and - (3 times)
8: i have not space here to enter on - (3 times)
9: all the species of the same genus are - (3 times)
10: the ordinary view of each species having been - (3 times)

Jan 12, 2023

text = ' '.join([t for t in re.sub(r'[^\w\s]', '', text.lower()).split(' ') if word not in stop])

Jan 11, 2023

import string
punc_free_text = text.translate(str.maketrans('', '', string.punctuation))

Jan 10, 2023

redacted = ' '.join([t if t not in secrets else '*' * len(t) for t in text])

Jan 9, 2023

from collections import Counter
bag_of_words = Counter(text.split(' '))

Jan 8, 2023

n = 5
n_grams = [(i, i+n, ' '.join(items[i:i+n])) for i in range(0, len(items))]

Join in…

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Published in Python in Plain English

New Python content every day. Follow to join our 3.5M+ monthly readers.

Written by Jeremy Brown

Software Engineer, originally from the U.S. and now living and working in Vienna, Austria. I write about Programming, Music, Machine Learning & NLP

No responses yet

Write a response