Skip to content

Instantly share code, notes, and snippets.

@ranlix
Last active December 31, 2015 00:29
Show Gist options
  • Save ranlix/7907360 to your computer and use it in GitHub Desktop.
Save ranlix/7907360 to your computer and use it in GitHub Desktop.
因为要将一个hls文件的本地文件给做出live(类似于播放列表.m3u8无限循环)的效果, 就用一个list来demo一下
# -*-coding:utf-8 -*-
import time
def ListRepeat(list, duration):
"""
call ListRepeat(list, duration), result should be like below:
['0', '1', '2', '3', '4', '5']
['1', '2', '3', '4', '5', '6']
['2', '3', '4', '5', '6', '7']
['3', '4', '5', '6', '7', '8']
['4', '5', '6', '7', '8', '9']
['5', '6', '7', '8', '9', '0']
['6', '7', '8', '9', '0', '1']
['7', '8', '9', '0', '1', '2']
['8', '9', '0', '1', '2', '3']
['9', '0', '1', '2', '3', '4']
"""
n = 0
while 1:
if n <= len(list):
if n <= len(list) - duration:
print list[n: n + duration]
else:
# len(list) - duration < n < len(list):
print list[n:] + list[:(duration - (len(list) - n))]
else:
n -= len(list)
print list[n: n + duration]
n += 1
time.sleep(1)
a = [str(i) for i in range(10)]
if __name__ == '__main__':
ListRepeat(a, 6)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment