diff --git a/listdata/__init__.py b/listdata/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/listdata/main.py b/listdata/main.py new file mode 100644 index 0000000..1ebed41 --- /dev/null +++ b/listdata/main.py @@ -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() diff --git a/listdata/panic.py b/listdata/panic.py new file mode 100644 index 0000000..4788994 --- /dev/null +++ b/listdata/panic.py @@ -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() diff --git a/listdata/panic2.py b/listdata/panic2.py new file mode 100644 index 0000000..25deea2 --- /dev/null +++ b/listdata/panic2.py @@ -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()