Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 126
Image: ubuntu2004
Kernel: Python 3 (system-wide)

Use a list comprehension to create a list containing all odd numbers from 1 to 50.

list = [] for i in range(50): if i%2 != 0: list.append(i)
list
[1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49]