Python for Rubyists, Part III: List Comprehensions

my_list = []print(my_list)
my_list = []for i in range(10):
my_list.append(i)
print(my_list)
my_list = [i for i in range(10)]print(my_list)
my_list = []for i in range(10):
if i % 2 == 0:
my_list.append(i)
print(my_list)
my_list = [i for i in range(10) if i % 2 == 0]print(my_list)

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Alyssa Lerner First

Alyssa Lerner First

Software developer and science/tech writer. Python, Ruby on Rails, JavaScript, React/Redux, Java. Fascinated by the amazing stories behind today’s tech.