Show code
squares = [x**2 for x in range(1, 6)]
print(squares)[1, 4, 9, 16, 25]
Gujuri Alekha
Oct 20, 2024
[] and typically consist of an expression and a for loop to iterate over the elements of an iterable.sorted() function or by calling the sort() method for lists in-place. You can also specify custom sorting criteria using the key argument.in keyword to check for membership, and the index() method to find the index of a specific element in a list. For dictionaries, you can use keys to access values efficiently.{'sorted_numbers : [1, 1, 2, 3, 3, 4, 5, 5, 5, 6, 9]'}
True
index of cheery is {index}
Get new notebooks as they're published
New parts are added to each track in order. Follow along:
@online{alekha2024,
author = {Alekha, Gujuri},
title = {Python {Data} {Structures:} {Lists,} {Sets} and
{Comprehensions}},
date = {2024-10-20},
url = {https://gujurialekha.github.io/blog/python/04-python-data-structures-and-collections.html},
langid = {en}
}