“Extra Credit Reflection for atUtexas”

by atUtexas

05 Dec 2022

Extra Credit Reflection

While working on my final project, I went back to review the online textbook chapters. I felt that lists, dictionaries, set and truples were seemed very similar to me. I further researched it and this is what I learned:

Lists use square brackets and Tuples use round braces. Another key difference is that Tuples are immutable and variables cant be changed. There are multiple ways of creating tuples. Sets use  keywords and its output is in curly braces. Dictionaries differ from these others. Lists and dictionaries are mutable which means values can change. Slices are possible in lists and tuples, but not dictionaries. 

Lists: If I want to extract a value for a list, I need to indicate the index number. Lists are  collections of data that don’t need random access. They are used when you need a simple collection that is modified frequently. 

Dictionaries: Extract values based on key. Duplicate keys are not allowed however, duplicate values are allowed. Use a dictionary when you need a logical association between key and value pair. And use it when you need a fast look up for the data. 

Tuples- want to extract a value from tuple, but indicate with index number. Use when data cant change. Tuples may use dictionaries. A tuple may represent a key.

Sets- used to store multiple items in a single variable.


#Lists- square braces
#list with mixed data types
my_list = [1, "Hello", 3.4]

#Tuples - round braces, Immutable- multiple ways of creating tuples
mytuple = ("apple", "banana", "cherry")

#Set- uses a set keyword, output in curly braces
myset = {"apple", "banana", "cherry"}

#Dictionaries- Curly braces make up of key value pairs
# dictionary with mixed keys
my_dict = {'name': 'John', 1: [2, 4, 3]}

Thank you for reading!

Here's a little about atUtexas Find atUtexas on Twitter, Github, and on the web.