“Lists” is a tutorial that covers the basics of working with lists in Python. The tutorial begins by defining what a list is and why it is useful in programming. It explains how to declare and initialize lists in Python and provides examples of different ways to create and modify lists.


#Adding data to an empty list
mylist = []
mylist.append(1)
mylist.append(2)
mylist.append(3)
print(mylist[0]) # prints 1
print(mylist[1]) # prints 2
print(mylist[2]) # prints 3

The tutorial covers a range of topics related to working with lists, including indexing and slicing lists, iterating over lists, and sorting and filtering lists. It also introduces some advanced list operations, such as list comprehensions and nested lists.

The tutorial also covers the concept of mutability in Python and how it relates to working with lists. It explains the difference between mutable and immutable objects and provides examples of how to modify lists in place.

Throughout the tutorial, there are numerous practical examples and exercises to help reinforce the concepts covered. These examples cover a range of real-world scenarios, such as working with data sets, filtering lists, and performing calculations using lists.


# prints out 1,2,3
for x in mylist:
    print(x)

#This will error, there is no integer at [10].
mylist = [1,2,3]
print(mylist[10])

The tutorial concludes by introducing some advanced topics related to working with lists, including copying and cloning lists, and how to use lists in conjunction with other Python data types, such as dictionaries and sets.

Lists Exercise Solution


# Code Completed
numbers = []
strings = []
names = ["John", "Eric", "Jessica"]

# write your code here
numbers.append(1)
numbers.append(2)
numbers.append(3)

strings.append("hello")
strings.append("world")

second_name = names[1]

# this code should write out the filled arrays and the second name in the names list (Eric).
print(numbers)
print(strings)
print("The second name on the names list is %s" % second_name)

Overall, “Lists” is an excellent resource for anyone looking to learn the basics of working with lists in Python. Its clear and concise explanations, practical examples, and interactive exercises make it an ideal resource for beginners and intermediate programmers alike. Whether you are looking to work with large data sets or simply want to better understand the basics of working with lists in Python, this tutorial is an excellent starting point. Next up is basic operators.