Geek Culture

A new tech publication by Start it up (https://medium.com/swlh).

Member-only story

Use These 5 Techniques to Write Concise Python Code

Yong Cui
5 min readAug 11, 2022

--

Photo by freestocks on Unsplash

1. Comprehensions and Generator Expressions

numbers = [-2, -1, 1, 2]
squares_list = [x*x for x in numbers]
assert squares_list == [4, 1, 1, 4]

--

--

Yong Cui
Yong Cui

Written by Yong Cui

Work at the nexus of biomedicine, data science & mobile dev. Author of Python How-to by Manning (https://www.manning.com/books/python-how-to).

Responses (1)