Skip to content

Instantly share code, notes, and snippets.

@kwekuboateng
Created October 12, 2016 14:36
Show Gist options
  • Save kwekuboateng/e20d2de1005c3ffe10c31452baf5194c to your computer and use it in GitHub Desktop.
Save kwekuboateng/e20d2de1005c3ffe10c31452baf5194c to your computer and use it in GitHub Desktop.
def suggest_playlist(track,time):
count = len(track)
for i in range(count):
for j in range(1, count-i):
if track[j-1][1]>track[j][1]:
(track[j-1],track[j])=(track[j],track[j-1])
sum = 0
selected_playlist = []
for i in track:
sum=sum+i[1]
if sum<=time:
selected_playlist.append(i)
return selected_playlist
tracks = [('kakai', 5), ('serwaa_akoto', 7), ('odo', 8), ('sika', 3), ('makoma', 7)]
print(suggest_playlist(tracks,16))
def get_position(list_of_list,value):
for i in list_of_list:
if value in i:
col = i.index(value)
row = list_of_list.index(i)
return [row, col]
print(get_position([[1,2,3,4],
[5,6,7,8],
[9,10,11,12,],
[13,14,15,16]],13)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment