100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
oplossingen extra oefeningen programmeren python dawynt dodona H8: Sets & dictionaries $3.75   Add to cart

Other

oplossingen extra oefeningen programmeren python dawynt dodona H8: Sets & dictionaries

 12 views  0 purchase
  • Course
  • Institution
  • Book

Oplossingen van extra gemaakte oefeningen op reeks 8 sets & dictionaires voor vak programmeren python van peter dawnyt op dodona, ugent

Preview 3 out of 23  pages

  • June 12, 2024
  • 23
  • 2023/2024
  • Other
  • Unknown
avatar-seller
H8: SETS AND DICTIONAIRIES

Dubbels
def dubbel(lijst):
if set(lijst) == len(lijst):
return None
else:
for element in lijst:
if lijst.count(element) ==2:
return element

def dubbels(lijst):
set1 = set(lijst)
set2 = set()
for karakter in lijst:
if lijst.count(karakter) > 1:
set2.add(karakter)
set1.discard(karakter)
return (set1, set2)

Kaukasus
def voorkomens(string):
dict = {}
string = string.lower()
for karakter in string:
if karakter.isalpha():
dict[karakter] = string.count(karakter)
return dict

def evenwichtig(string):
dict = voorkomens(string)
voorkomen = []
for letter in dict:
if dict[letter] not in voorkomen:
voorkomen.append(dict[letter])
if len(voorkomen) == 1 and voorkomen[0] >=2:
return True
return False

Wat zit er in de zak?
def vullen(string):
dict = {}
for karakter in string:
dict[karakter] = string.count(karakter)
return dict

def omschrijving(zak):
dict = {}
verzameling= set()
for letter,waarde in zak.items():

if waarde not in dict:
dict[waarde] = set()
dict[waarde].add(letter)
return dict

def controleer(collectie,zak):
verschillende = set(collectie)
for letter in verschillende:
if letter not in zak:

, return False
aantal = collectie.count(letter)
if aantal > zak[letter]:
return False
return True


def controleer(collectie,zak):
verschillende = set(collectie)
for letter in verschillende:
if letter not in zak:
return False
aantal = list(collectie).count(letter)
if aantal > zak[letter]:
return False
return True


def wegnemen(collectie,zak):
assert controleer(collectie,zak), "niet alle letters zitten in het zakje"
verschillende = set(collectie)
for letter in verschillende:
aantal = list(collectie).count(letter)
zak[letter] = zak[letter] - aantal
if zak[letter] ==0:
del zak[letter]


Zalig kerstfeest
def controleer(string,lengte = 10):
#moet uit 10 verschillende hoofdletters bestaan en moet een string zijn
return isinstance(string,str) and len(set(string)) == len(string) == lengte

def oplossing(woord,cijfers="0123456789"):
assert (
controleer(woord) and woord.isupper()
and
controleer(cijfers) and cijfers.isdigit()
),"ongeldige oplossing"

dict = {}
for letter in woord:
index = woord.index(letter)
cijfer = cijfers[index]
dict[letter] = int(cijfer)
return dict

def controleer_raadsel(zin,dict):
for key in dict:
if key not in zin:
return False
return True


#moet ook gescheiden zijn door spaties

def vervangen(zin,dict):
assert controleer_raadsel(zin,dict), "ongeldig raadsel"
antwoord = ""
for karakter in zin:

, if karakter.isalpha():
antwoord += str(dict[karakter])
else:
antwoord += " "
return antwoord

import math
def iskwadraat(getal):
return round(math.sqrt(getal)) ** 2 == getal


def iscorrect(zin,woord,opl="0123456789"):
dict = oplossing(woord,cijfers=opl)
assert controleer_raadsel(zin,dict), "ongeldig raadsel"

antwoord = vervangen(zin,dict)
lijst = antwoord.split()
for element in lijst:
if iskwadraat(int(element)) is False:
return False
return True

Sneeuwbalgetallen
def letterverdeling(string):
dict = {}
verschillende = set()
string = string.upper()
for karakter in string:
if karakter.isalpha() and karakter not in verschillende:
verschillende.add(karakter)
dict[karakter] = string.count(karakter)
return dict

def sneeuwbal(string):
dict = letterverdeling(string)
voorkomens = []
for letter in dict:
voorkomens.append(dict[letter])


if len(set(voorkomens)) == len(voorkomens):
for i in range(1,len(voorkomens)+1):
if i not in voorkomens:
return False
else:
return False

return True

def pyramide(string):
verdeling = letterverdeling(string) #dict
voorkomens = []
for letter in verdeling:
voorkomens.append(verdeling[letter])

gesorteerde_lijst = sorted(list(set(voorkomens)))
for i in range(len(gesorteerde_lijst)-1):
karakter = gesorteerde_lijst[i]
volgende = gesorteerde_lijst[i+1]
if karakter > volgende:

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying these notes from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller hannahmeuleman. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy these notes for $3.75. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

67474 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy study notes for 14 years now

Start selling
$3.75
  • (0)
  Add to cart