-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathListComprehension.py
More file actions
48 lines (39 loc) · 1.99 KB
/
Copy pathListComprehension.py
File metadata and controls
48 lines (39 loc) · 1.99 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
def playlist(artists_song, friends_artists):
friends_list = []
for artist in friends_artists:
for k, v in artists_song.items():
for songs in v:
if artist in k:
friends_list.append(songs)
if friends_list:
friends_list.sort()
return friends_list
return "I guess I don't mind ads on the radio that much"
# Below are some lines of code that will test your function.
# You can change the value of the variable(s) to test your
# function with different inputs.
#
# If your function works correctly, this will originally
# print: ["It's a long way to the top", "Memories", "Payphone", "Sugar", "TNT", "Thunderstruck"]
artists_and_songs = {"Beyonce": ["Halo", "Run the World", "Irreplaceable"], \
"Maroon 5": ["Sugar", "Payphone", "Memories"], "Harry Styles": \
["Sign of the Times", "Adore You", "Falling"], "AC/DC": \
["TNT", "It's a long way to the top", "Thunderstruck"]}
friends_artists = ["Maroon 5", "AC/DC", "Tame Impala"]
print(playlist(artists_and_songs, friends_artists))
print()
# convert the above code to a list comprehension:
def playlist(artists_song, friends_artists):
output = [songs for k, v in artists_song.items() for songs in v for x in friends_artists if x in k ]
if output:
output.sort()
return output
return "I guess I don't mind ads on the radio that much"
artists_and_songs = {"Beyonce": ["Halo", "Run the World", "Irreplaceable"], \
"Maroon 5": ["Sugar", "Payphone", "Memories"], "Harry Styles": \
["Sign of the Times", "Adore You", "Falling"], "AC/DC": \
["TNT", "It's a long way to the top", "Thunderstruck"]}
friends_artists = ["Maroon 5", "AC/DC", "Tame Impala"]
print(playlist(artists_and_songs, friends_artists))
### Mancala game:
if (sum(twoDList[0][1:]) != 0) or (sum(twoDList[1][:-1])) != 0: