Skip to content

Commit 312a235

Browse files
authored
Added Empty List Challenge (#48)
* Added template * Updated template * Add files via upload * Added solution file
1 parent 654d18d commit 312a235

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
## How to Empty a List in Python Challenge
2+
3+
The following challenge was described in the article
4+
[How to Empty a List in Python](https://therenegadecoder.com/code/how-to-check-if-a-key-exists-in-a-dictionary-in-python/#challenge).
5+
6+
### Challenge Description
7+
8+
Write a function that empties a list only under certain conditions. Since we’re dealing with anime,
9+
the conditions will be as follows:
10+
11+
- Empty the input list if it meets any of the following conditions:
12+
- Contains any duplicate shows
13+
- Contains more than 17 shows
14+
- Contains shows that feature the word “Your” in the title
15+
16+
### Expected Behavior
17+
18+
```python
19+
to_empty_or_not_to_empty(["Haruhi", "Haruhi"]) # Empty!
20+
to_empty_or_not_to_empty(["Nagatoro"] * 17) # Empty!
21+
to_empty_or_not_to_empty(["Your Lie in April"]) # Empty!
22+
to_empty_or_not_to_empty(["Steins;Gate", "My Hero Academia", "A Place Further Than the Universe"]) # Do NOT empty!
23+
```
24+
25+
### Example Solution
26+
27+
![Solution](solution.jfif)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
def to_empty_or_not_to_empty(anime: list):
2+
hasDuplicates = len(set(anime)) != len(anime)
3+
hasSeventeenShows = len(anime) == 17
4+
hasYourTitle = any("Your" in word for word in anime)
5+
if hasDuplicates or hasSeventeenShows or hasYourTitle:
6+
anime.clear()
35.4 KB
Binary file not shown.

0 commit comments

Comments
 (0)