-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lecture "Organising information: unordered structures", exercise 2 #22
Comments
|
|
The status of my_set will be: |
|
After |
|
|
Starting Set: my_set.remove("Bilbo"): my_set = {'Pippin', 'Sam', 'Frodo', 'Merry'} |
|
|
|
|
When I ran these all in PythonTutor it would switch the order of the objects. Sets are unordered so it doesn't really matter I just wondering how it decides where to put them. |
|
`my_set = set(({'Frodo', 'Sam', 'Pippin', 'Merry', 'Bilbo'})) my_set.remove("Bilbo") #{'Sam', 'Frodo', 'Merry', 'Pippin'} my_set.add("Galadriel") #{'Sam', 'Galadriel', 'Frodo', 'Merry', 'Pippin'} my_set.update(my_other_set) #output {'Sam', 'Galadriel', 'Frodo', 'Saruman', 'Gandalf', 'Merry', 'Pippin'} |
|
|
|
lotr_set=set() lotr_set.remove("Bilbo") #the element Frodo in the added set will replace the same value in lotr_set, because it is not possible to have the same #value twice in a set |
Consider the set created in the first exercise, stored in the variable
my_set
. Describe the status of my_set
after the execution of each of the following operations:my_set.remove("Bilbo")
, my_set.add("Galadriel")
,my_set.update(set({"Saruman", "Frodo", "Gandalf"}))
.The text was updated successfully, but these errors were encountered: