File tree Expand file tree Collapse file tree 3 files changed +33
-0
lines changed
challenges/how-to-empty-a-list Expand file tree Collapse file tree 3 files changed +33
-0
lines changed Original file line number Diff line number Diff line change
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 )
Original file line number Diff line number Diff line change
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 ()
You can’t perform that action at this time.
0 commit comments