Gestione delle liste

This commit is contained in:
Fabio Scotto di Santolo
2021-06-26 13:56:43 +02:00
parent a9350a62a3
commit a814af5ba0
4 changed files with 77 additions and 0 deletions

40
listdata/main.py Normal file
View File

@@ -0,0 +1,40 @@
from collections import Counter
def main():
# Tuple
vowels = ('a', 'e', 'i', 'o', 'u')
word = 'Supercalifragilisticexpialidocious'
# Loop over string
for letter in word:
if letter in vowels:
print(letter)
# Count vowels in a word
vowels_in_word = [letter for letter in word.lower() if letter in vowels]
print(Counter(vowels_in_word), '\n')
# List share reference between first and second
first = [1, 2, 3, 4, 5]
print(f"{first=} (initial)")
second = first
print(f"{second=} (initial)")
second.append(6)
print(f"{second=} (post append)")
print(f"{first=} (post append)")
# If you want create a list's copy you must to use copy method
print("Third is a copy of second")
third = second.copy()
print(f"{third=} (pre append)")
third.append(7)
print(f"{third=} (post append)")
print(f"{second=} (post append)")
if __name__ == '__main__':
main()