我正在尝试为电影播放系统制作一个提示列表。
每次创建一个cue我都想在cue对象中添加一个id 。
(看起来像什么)
{ "name": "Cue One", "length": 5000, "id": xxx }每个提示对象将存储在提示列表中。 但是,我想知道为每个提示生成ids的最佳方法,因为它们最终将在列表中通过ID查找。
我知道我可以做类似的事情( max[cue.id for cues in cuelist] + 1 )或者我可以使用random模块并检查randint是否不在cues id中,但是我不知道最多的是什么“合法”的方式是这样做的。
是否有针对此类问题的特定技术或算法?
I am trying to make a list of cues for a movie playback system.
Every time a cue is created I want to add an id to the cue object.
(Which looks something like)
{ "name": "Cue One", "length": 5000, "id": xxx }Each cue object will get stored in a list of cues. However, I want to know the best way to generate ids for each cue since they will ultimately be looked up, in the list, by ID.
I know I could do something like (max[cue.id for cues in cuelist] + 1) or I could use the random module and check to see if the randint is not in the cues id, however I do not know what the most "legit" way to do this is.
Is there some specific technique or algorithm for this sort of problem?
最满意答案
我认为您正在寻找的是UUIDs参考python文档: https : //docs.python.org/2/library/uuid.html
I think what you are looking for are UUIDs Refering to python documentation: https://docs.python.org/2/library/uuid.html
更多推荐
发布评论