5 Python One-Liners That Will Change How You Code
Most Python devs write 10 lines where 1 would do. Here are 5 that'll make you rethink everything:
1. Flatten a nested list
flat = [x for sub in nested for x in sub]2. Swap two variables
a, b = b, a3. Count word frequency in a sentence
from collections import Counter
freq = Counter(sentence.split())4. Read an entire file into a string
content = open("file.txt").read()5. Filter a list by condition
evens = [x for x in nums if x % 2 == 0]Python's power is in its simplicity. Most people overcomplicate it.
I'm building Code Serpent — a community for Python devs at every level. We do code reviews, weekly challenges, tutorials from basics to advanced ML/data science, and we actually build things together.
If you write Python (or want to start), come through.