Lecture "Organising information: unordered structures", exercise 1
essepuntato opened this issue · 21 comments
Write a code in Python to create a set of the following elements: "Bilbo"
, "Frodo"
, "Sam"
, "Pippin"
, "Merry"
.
my_set = set()
my_set.add('Bilbo')
my_set.add('Frodo')
my_set.add('Sam')
my_set.add('Pippin')
my_set.add('Merry')
my_set = set()
my_set.add("Bilbo")
my_set.add("Frodo")
my_set.add("Sam")
my_set.add("Pippin")
my_set.add("Merry")
my_set = set()
my_set.add("Bilbo")
my_set.add("Frodo")
my_set.add("Sam")
my_set.add("Pippin")
my_set.add("Merry")
lotr_set = set()
lotr_set.add('Bilbo')
# current state {'Bilbo'}
lotr_set.add('Frodo')
# current state {'Bilbo', 'Frodo'}
lotr_set.add('Sam')
# current state {'Sam', 'Frodo', 'Bilbo'}
lotr_set.add('Pippin')
# current state {'Sam', 'Bilbo', 'Pippin', 'Frodo'}
lotr_set.add('Merry')
print(lotr_set)
# output {'Frodo', 'Sam', 'Merry', 'Pippin', 'Bilbo'}
fellowship_hobbits = set()
fellowship_hobbits.add("Bilbo")
fellowship_hobbits.add("Frodo")
fellowship_hobbits.add("Sam")
fellowship_hobbits.add("Pippin")
fellowship_hobbits.add("Merry")
my_set = {'Bilbo', 'Frodo', 'Sam', 'Pippin', 'Merry'}
my_set=set()
my_set.add("Bilbo")
my_set.add("Frodo")
my_set.add("Sam")
my_set.add("Pippin")
my_set.add("Merry")
output=my_set
my_set= set()
my_set.add("Bilbo")
my_set.add("Frodo")
my_set.add("Sam")
my_set.add("Merry")
my_set.add("Pippin")
print my_set
char_set = set()
char_set.add("Bilbo")
char_set.add("Frodo")
char_set.add("Sam")
char_set.add("Pippin")
char_set.add("Merry")
# char_set = { 'Sam', 'Bilbo', 'Frodo', 'Merry', 'Pippin'}
# Write a code in Python to create a set of the following elements:
# "Bilbo", "Frodo", "Sam", "Pippin", "Merry".
lotr_set = set()
lotr_set.add("Bilbo")
lotr_set.add("Frodo")
lotr_set.add("Sam")
lotr_set.add("Pippin")
lotr_set.add("Merry")
print(lotr_set)
`my_set = set ()
my_set.add("Bilbo")
my_set.add("Frodo")
my_set.add("Sam")
my_set.add("Pippin")
my_set.add("Mary")
print(my_set)`
# Write a code in Python to create a set of the following elements:
# "Bilbo", "Frodo", "Sam", "Pippin", "Merry".
my_set = {"Bilbo", "Frodo", "Sam", "Pippin", "Merry"}
print(my_set)
lotr_set={"Bilbo", "Frodo", "Sam", "Pippin", "Merry"}
hobbit_set = set()
hobbit_set.add("Bilbo")
hobbit_set.add("Frodo")
hobbit_set.add("Sam")
hobbit_set.add("Pippin")
hobbit_set.add("Merry")
print(hobbit_set)
# output: {'Merry', 'Sam', 'Frodo', 'Bilbo', 'Pippin'}
`
hobbit_set = set()
hobbit_set.add("Bilbo")
hobbit_set.add("Frodo")
hobbit_set.add("Sam")
hobbit_set.add("Pippin")
hobbit_set.add("Merry")
print(hobbit_set)
`
my_lotr_set = set()
my_lotr_set.add("Bilbo")
my_lotr_set.add("Frodo")
my_lotr_set.add("Sam")
my_lotr_set.add("Pippin")
my_lotr_set.add("Merry")
print(my_lotr_set)
# Output: my_lotr_set = {"Bilbo", "Frodo", "Sam", "Pippin", "Merry"}
my_set = set()
my_set.add("Bilbo")
my_set.add("Frodo")
my_set.add("Pippin")
my_set.add("Marry")
print(my_set)
LOTR_set = set()
LOTR_set.add("Bilbo")
LOTR_set.add("Frodo")
LOTR_set.add("Sam")
LOTR_set.add("Pippin")
LOTR_set.add("Merry")
print(LOTR_set)
lotr_set=set()
lotr_set.add("Bilbo")
lotr_set.add("Frodo")
lotr_set.add("Sam")
lotr_set.add("Pippin")
lotr_set.add("Merry")
my_set = {"Bilbo", "Frodo", "Sam", "Pippin", "Merry"}
print(my_set)
Hi all,
thanks for your answer. Just a comment for @giorgiasampo: print my_set
is a Python 2 construct, while in Python 3 you should use print(my_set)
– print
is a proper function in Python 3.