Skip to content

Commit 6de9489

Browse files
committed
tuple unpacking added
1 parent 3603a1d commit 6de9489

File tree

4 files changed

+36
-24
lines changed

4 files changed

+36
-24
lines changed

madlib_copycat.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ def msgs_to_user():
1616

1717

1818
def play_copycat_game():
19-
print("I am a copy cat! I will reapeat whatever you type.")
20-
print("I am a copy cat! I will reapeat whatever you type.")
19+
print("I am a copy cat! I will repeat whatever you type.")
20+
print("I am a copy cat! I will repeat whatever you type.")
2121
print("Enter 'q' to end the program.")
2222
while True:
2323
text = input("What do you have to say?: ")

main.py

-22
This file was deleted.

tables.py

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
'''Python Quick Codes: Generate table of a given number.'''
2+
3+
14
print("Enter a number and I will print it's table.")
25
print("Enter 'quit' to end the program.")
36

tuple_unpacking.py

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
'''Python Quick Code to demonstrate:
2+
1. Use of counter from inbuilt collection module of Python.
3+
2. Function returning more than one value.
4+
'''
5+
6+
from collections import Counter
7+
8+
9+
def get_vowel_and_consonants(sentence):
10+
vowels = []
11+
consonants = []
12+
for i in sentence:
13+
if i in ['a', 'e', 'i', 'o', 'u']:
14+
vowels.append(i)
15+
else:
16+
consonants.append(i)
17+
18+
return vowels, consonants
19+
20+
21+
sentence = "A quick brown fox jumps over the lazy dog"
22+
23+
# Tuple unpacking, more than two values from a return statement will be a tuple
24+
vowels, consonants = get_vowel_and_consonants(sentence)
25+
26+
# Get occurrences of each alphabet. Counter returns a dictionary.
27+
occurrences = Counter(sentence)
28+
29+
print(f"Vowels: {vowels}")
30+
print(f"Consonants: {consonants}")
31+
print(f"Occurrences dictionary: {occurrences}")

0 commit comments

Comments
 (0)