Skip to content
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 1 #22

Open
essepuntato opened this issue Nov 9, 2021 · 20 comments
Open
Labels

Comments

@essepuntato
Copy link
Contributor

Write a code in Python to create a set of the following elements: "​Bilbo"​, "​Frodo"​, "​Sam"​, "​Pippin"​, "​Merry"​.

@11051620
Copy link

my_set = {'Bilbo', 'Frodo', 'Sam', 'Pippin', 'Merry'}

@katya-avem
Copy link

my_first_set = {'Bilbo', 'Frodo', 'Sam', 'Pippin', 'Merry'}

@chloeppd
Copy link

my_set = {"Bilbo", "Frodo", "Sam", "Pippin", "Merry"}

@elizastuglik
Copy link

mySet = {"Bilbo", "Frodo", "Sam", "Pippin", "Merry"}

@tommasobattisti
Copy link

my_set = set()
my_set.add('Bilbo')
my_set.add('Frodo')
my_set.add('Sam')
my_set.add('Pippin')
my_set.add('Merry')

otherwise:
my_set = {"Bilbo", "Frodo", "Sam", "Pippin", "Merry"}

@martasoricetti
Copy link

image

@OrsolaMBorrini
Copy link

Either

lotr_set = set()
lotr_set.add("Bilbo")
lotr_set.add("Frodo")
lotr_set.add("Sam")
lotr_set.add("Pippin")
lotr_set.add("Merry")

or
lotr_set = {"Bilbo", "Frodo", "Sam", "Pippin", "Merry"}

@Bianca-LM
Copy link

my_set = set ()
my_set.add("Bilbo")
my_set.add("Frodo")
my_set.add("Sam")
my_set.add("Pippin")
my_set.add("Merry")

@giorgimariachiara
Copy link

my_set = {"Bilbo", "Frodo", "Sam", "Pippin", "Merry"}

@olgagolgan
Copy link

image

since it is unordered, I tried to run the code multiple times and I obtained different sets

image

@ManueleVeggi
Copy link

ManueleVeggi commented Nov 12, 2021

my_list = ["Bilbo", "Frodo", "Sam", "Pippin", "Merry"]
my_set = set()

for item in my_list:
    my_set.add(item)

print(my_set)

A shorter way is the line my_set = set({"​Bilbo"​, "​Frodo"​, "​Sam"​, "​Pippin"​, "​Merry"​})

@francescabudel
Copy link

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)

{'Merry', 'Frodo', 'Sam', 'Bilbo', 'Pippin'}

@SaraVell1
Copy link

image

@angstigone
Copy link

Schermata 2021-11-12 alle 17 40 20

@AmeliaLamargese
Copy link

my_set = set({" Bilbo", " Frodo", " Sam", " Pippin", " Merry"})

@federicabonifazi
Copy link

image

@AnastasiyaSopyryaeva
Copy link

my_set = {'Bilbo', 'Frodo', 'Sam', 'Pippin', 'Merry'}

@sanyuezoe
Copy link

the_first_set = set()
the_first_set.add('Bilbo')
the_first_set.add('Frodo')
the_first_set.add('Sam')
the_first_set.add('Pippin')
the_first_set.add('Merry')
print(the_first_set)

@teragramgius
Copy link

my_set = set()
my_set.add('Bilbo')
my_set.add('Frodo')
my_set.add('Sam')
my_set.add('Pippin')
my_set.add('Merry')
print (my_set)

@GaiaOrtona
Copy link

'''
my_first_set = {"Bilbo", "Frodo", "Sam", "Pippin", "Merry"}
#otherwise you can also do it this way
my_second_set = set()
my_second_set.add("Bilbo")
my_second_set.add("Frodo")
my_second_set.add("Sam")
my_second_set.add("Pippin")
my_second_set.add("Merry")
'''

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests