
ALT >>> from itertools import combinations >>> from difflib import SequenceMatcher >>> tags = 'python pythonista developer development'.split() >>> for pair in combinations(tags, 2): ... similarity = SequenceMatcher(None, *pair).ratio() ... print(pair, similarity) ... ('python', 'pythonista') 0.75 ('python', 'developer') 0.13333333333333333 ('python', 'development') 0.23529411764705882 ('pythonista', 'developer') 0.10526315789473684 ('pythonista', 'development') 0.19047619047619047 ('developer', 'development') 0.8
![import codecs import contextlib import io SHORT_TITLE = "Zen of Python {number}: {title}" with contextlib.redirect_stdout(io.StringIO()): import this import_this_output = codecs.decode(this.s, 'rot13') for i, title in enumerate(import_this_output.splitlines()[2:], start=1): print(SHORT_TITLE.format(number=i, title=title)) # Zen of Python 1: Beautiful is better than ugly. # Zen of Python 2: Explicit is better than implicit. # Zen of Python 3: Simple is better than complex. # Zen of Python 4: Complex is better than complicated. # ...](https://pbs.twimg.com/media/GcL_85rXgAAHQVf.jpg?name=small&format=webp)
ALT import codecs import contextlib import io SHORT_TITLE = "Zen of Python {number}: {title}" with contextlib.redirect_stdout(io.StringIO()): import this import_this_output = codecs.decode(this.s, 'rot13') for i, title in enumerate(import_this_output.splitlines()[2:], start=1): print(SHORT_TITLE.format(number=i, title=title)) # Zen of Python 1: Beautiful is better than ugly. # Zen of Python 2: Explicit is better than implicit. # Zen of Python 3: Simple is better than complex. # Zen of Python 4: Complex is better than complicated. # ...

ALT >>> from functools import cache >>> from timeit import timeit >>> def nocache_fib(n): ... if n < 2: ... return n ... return nocache_fib(n - 1) + nocache_fib(n - 2) ... >>> @cache ... def cached_fib(n): ... if n < 2: ... return n ... return cached_fib(n - 1) + cached_fib(n - 2) ... >>> timeit("nocache_fib(40)", "from __main__ import nocache_fib", number=1) 38.08430259900001 >>> timeit("cached_fib(40)", "from __main__ import cached_fib", number=1) 6.163200009723369e-05












![>>> names = ["April", "Eva", "Herman", "Antonio"] >>> sorted(names) ['Antonio', 'April', 'Eva', 'Herman'] >>> names # unchanged ['April', 'Eva', 'Herman', 'Antonio'] >>> names.sort() # returns None >>> names # changed ['Antonio', 'April', 'Eva', 'Herman']](https://pbs.twimg.com/media/GbtEy0rW8AwMswu.jpg?name=small&format=webp)



