Gestione delle liste
This commit is contained in:
0
listdata/__init__.py
Normal file
0
listdata/__init__.py
Normal file
40
listdata/main.py
Normal file
40
listdata/main.py
Normal 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()
|
||||||
21
listdata/panic.py
Normal file
21
listdata/panic.py
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
def main():
|
||||||
|
phrase = "Don't panic"
|
||||||
|
plist = list(phrase)
|
||||||
|
print(phrase)
|
||||||
|
print(plist)
|
||||||
|
|
||||||
|
# I insert here my code
|
||||||
|
for i in range(3):
|
||||||
|
plist.pop()
|
||||||
|
plist.pop(0)
|
||||||
|
plist.remove("'")
|
||||||
|
plist.extend([plist.pop(), plist.pop()])
|
||||||
|
plist.insert(2, plist.pop(3))
|
||||||
|
|
||||||
|
new_phrase = ''.join(plist)
|
||||||
|
print(plist)
|
||||||
|
print(new_phrase)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
16
listdata/panic2.py
Normal file
16
listdata/panic2.py
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
def main():
|
||||||
|
phrase = "Don't panic"
|
||||||
|
plist = list(phrase)
|
||||||
|
print(phrase)
|
||||||
|
print(plist)
|
||||||
|
|
||||||
|
# I insert here my code
|
||||||
|
new_phrase = ''.join(plist[1:3])
|
||||||
|
new_phrase = new_phrase + ''.join([plist[5], plist[4], plist[7], plist[6]])
|
||||||
|
|
||||||
|
print(plist)
|
||||||
|
print(new_phrase)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
Reference in New Issue
Block a user