Search⌘ K
AI Features

Collections: Lists, Tuples, Sets, and Dictionaries

Explore Python collections such as lists, tuples, sets, and dictionaries to manage and manipulate data in engineering projects. Understand key methods like append, slicing, and dictionary lookups to efficiently handle different data types and structures.

We'll cover the following...

Lists

The next datatype is the list. A list can be a collection of anything; think of it as a one-dimensional array. It has one “row” but as many “columns” as you want. Usually, the data types are the same in a given list, but that convention does not have to be followed. Lists can be sliced just like strs. The official datatype name is list or [], so do not name any list variable plain old list!

Python 3.8
list_of_nums = [1, 2, 3, 4, 5]
print('list_of_nums[0] -->', list_of_nums[0])
print('len(list_of_nums) -->', len(list_of_nums))

You can add to lists by using the append() method, which accepts one argument: the variable you want to add to the list.

Python 3.8
list_of_nums = [1, 2, 3, 4, 5]
list_of_nums.append(7)
print(list_of_nums)

A list is almost exactly like an array type in MATLAB. There are ...