-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday20_speakPython9.py
More file actions
107 lines (72 loc) · 2.7 KB
/
Copy pathday20_speakPython9.py
File metadata and controls
107 lines (72 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
""" 🧠 **Day 20 – Speak Python 9**
### 👉 Focus Areas:
* List Methods
* String Cleaning
* Logic Building
* Beginner-Friendly Micro Projects"""
""" ✅ **Problem 1: Remove Duplicates from List**
📌 **Task:**
Write a function that removes duplicates from a list and returns the unique elements in the same order as they first appeared.
📎 **Example:**
```python
remove_duplicates([1, 2, 2, 3, 4, 4, 5]) ➞ [1, 2, 3, 4, 5]
remove_duplicates(["apple", "banana", "apple"]) ➞ ["apple", "banana"]
```
💡 **Hint:** Use a `set()` to track seen items.
⏱️ **Target Time:** 10 minutes"""
# def remove_duplicates(lst):
# return list(set(lst))
# print(remove_duplicates([1, 2, 2, 3, 4, 4, 5, 1, 2, 2, 3, 4, 4, 5]))
# print(remove_duplicates(["apple", "banana", "apple"]))
""" 🧪 **Problem 2: Clean Up String**
📌 **Task:**
Write a function that removes punctuation (like `.`, `,`, `!`, `?`) from a sentence.
📎 **Example:**
```python
clean_text("Hello, world!") ➞ "Hello world"
clean_text("Python is fun!!!") ➞ "Python is fun"
```
🎯 **Focus:** String filtering, loops
💡 **Hint:** Use `string.punctuation` from the `string` module.
⏱️ **Target Time:** 12 minutes"""
# def clean_text(s):
# puns = [".", ",", "!", "?"]
# rm_pun = ""
# for char in s:
# if char not in puns:
# rm_pun += char
# return rm_pun
# print(clean_text("Hello, world!"))
# print(clean_text("Python is fun!!!"))
""" ⚒️ **Problem 3: Micro Project – Shopping List Builder**
📌 **Task:**
Create a function that takes input as a comma-separated string (e.g., `"milk, eggs, bread, milk"`) and returns a cleaned shopping list (unique items, capitalized, no spaces).
📎 **Example:**
```python
build_shopping_list("milk, eggs, bread, milk") ➞ ['Milk', 'Eggs', 'Bread']
```
🎯 **Focus:** String splitting, formatting, list building
💡 **Hint:** Use `.split(',')`, `.strip()`, `.capitalize()`
⏱️ **Target Time:** 15 minutes"""
def build_shopping_list(s):
items = s.split(",")
seen = []
for item in items:
cleaned = item.strip().capitalize()
if cleaned not in seen:
seen.append(cleaned)
return seen
print(build_shopping_list("milk, eggs, bread, milk"))
print(build_shopping_list("milk, eggs, eggs, bread, eggs, milk"))
""" ✅ Bonus Idea (Optional):
**📌 Task:** Write a function that counts how many unique vowels are used in a word.
📎 **Example:**
python
unique_vowel_count("education") ➞ 5
unique_vowel_count("sky") ➞ 0"""
def unique_vowel_count(word):
vowels = set("aeiou")
return len(set(word.lower()) & vowels)
print(unique_vowel_count("education"))
print(unique_vowel_count("sky"))
print(unique_vowel_count("cooperation"))