我有一个数组:
filename,number of times to show it
示例:
video1.mp4,50
video2.mp4,100
video3.mp4,50
video4.mp4,150
创建播放列表文件的最佳方式是什么,例如:
video4
video2
video4
video1
video2
video3
video4
也许就像:
取max show_times variable =它是一些show块,并尝试使每个块像:
video_files_list =((file1,50),(file2,100),(file3,300))
播放列表= []
表示i = 0到max_show_times:// max_show_times = 300
对于video_files_list中的k,:
if i % (max_show_times/(max_show_times/k[1])) ==0:
// k [1] - 对于file1是50,对于file2是100
playlist.add(k[0])
答案 0 :(得分:0)
你的算法可以用这种方式实现
from itertools import imap
def generate_playlist(pairs):
'''
@param pairs: list of pairs, first element is a file name, second - repetition amount
@return: generator for playlist items
'''
max_show_times = max(imap(second, pairs))
for i in xrange(max_show_times):
for file_path, repetition_count in pairs:
if i % (max_show_times / repetition_count) == 0:
yield file_path
def second(col):
if col and len(col) > 1:
return col[1]
playlist = generate_playlist(file_to_count_pairs)
playlist = imap(get_file_name_without_ext, playlist)