From 6db03d7d881df669825515e37cd7e43d5dc9772f Mon Sep 17 00:00:00 2001 From: Fabio Scotto di Santolo Date: Sat, 26 Jun 2021 16:39:10 +0200 Subject: [PATCH] Test sulle strutture dati (dizionari, insiemi e tuple) --- dictdata/__init__.py | 0 dictdata/main.py | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 dictdata/__init__.py create mode 100644 dictdata/main.py diff --git a/dictdata/__init__.py b/dictdata/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/dictdata/main.py b/dictdata/main.py new file mode 100644 index 0000000..a07abd1 --- /dev/null +++ b/dictdata/main.py @@ -0,0 +1,40 @@ +def main(): + # Dictionary data structure (aka Hashtable, Map, ecc.) + person = { + 'Name': 'Ford Prefect', + 'Gender': 'Male', + 'Occupation': 'Researcher', + 'Home Planet': 'Betelguese Seven' + } + + print(f"Initial values:\n{person=}\n") + + # Lookup values by key + print(f"Fetch name value from dict {person['Name']=}\n") + + # Add new pair key/value + person['Age'] = 33 + print(f"After add new key Age:\n{person=}\n") + + # Count vowel frequency in a word + word = "Supercalifragilisticexpialidocious" + frequency = {'a': 0, 'e': 0, 'i': 0, 'o': 0, 'u': 0} + for c in word.lower(): + if c in frequency: + frequency[c] += 1 + + print(f"{frequency=}\n") + + for k, v in sorted(frequency.items()): + print(f"{k} was found {v} time(s)") + + # Set data structure + print("\nSet data structure") + vowels = set('aeiou') + found = vowels.intersection(word) + for vowel in found: + print(vowel) + + +if __name__ == '__main__': + main()