

Tweetable Python – Tweetable Python 3.7 Documentation
source link: https://www.tuicool.com/articles/hit/biErIzm
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Each programs in this books fits in a single tweet (280 chars or less) and does something useful, powerful or fun.
These programs will serve a reference, inspire and delight.
In most cases, but not always, the code is Pythonic
, without any obfuscation or code golfing.
These programs serve as a testament to Python’s power, conciseness and clarity
Take this example
import random, string "".join( [random.choice(string.ascii_letters + string.digits) for i in range(8)] )
In less than a 100 chars, you can generate truly random passwords.
Now look at this function which fits a tweet.
ch= "█" def col(sz): mn,mx=min(sz),max(sz) df = (mx-mn)//8 bkt = [(el-mn)//df for el in sz] hrz = [f"{b}{c}" for b,c in [(ch*(el+1)," "*(8-el)) for el in bkt] ] return "\n".join([" ".join(el) for el in list(map(list, zip(*hrz)))[::-1]])
You can now generate a columns chart for any integer series, visible on terminals.
In [2]: import random In [3]: series = [random.randint(10, 99) for _ in range(25)] In [4]: print(col(series)) █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █
We will look at things like file manipulation, file conversion, password generation, ascii art and even some games. This book is inspired by Peteris Krumins’ Perl One Liners.
Note
Judge me by my size, do you? Hmm, hmm. - Yoda.
Lets get started.
Recommend
-
71
-
46
-
4
queue — A synchronized queue class¶ Source code:
-
6
Built-in Types¶ The following sections describe the standard types that are built into the interpreter. The principal built-in types are numerics,...
-
6
6.2. Atoms¶ Atoms are the most basic elements of expressions. The simplest atoms are identifiers or literals. Forms enclosed in parentheses, brackets or bra...
-
4
Introduction: I’ve seen multiple instances at work, in source code examples, and even from open source projects where the documentation of the code was non-existent or insufficient. A lot of times as software develop...
-
8
pickle — Python object serialization¶ Source code:
-
6
Built-in Functions¶ The Python interpreter has a number of functions and types built into it that are alw...
-
5
-
6
Building Python Project Documentation With MkDocs In this course, you’ll learn how to quickly build documentation for a Python package using MkDocs and mkdocstrings
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK