1

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?

Startec
  • 12,496
  • 23
  • 93
  • 160
  • 3
    Why not use [uuid](https://docs.python.org/3/library/uuid.html) to generate your ids? – idjaw Mar 07 '16 at 20:52
  • 1
    Why not store the cues in a `list`. The `id` field becomes redundant when you can look them up by index. – quamrana Mar 07 '16 at 20:55

1 Answers1

3

I think what you are looking for are UUIDs Refering to python documentation: https://docs.python.org/2/library/uuid.html

drgn
  • 1,080
  • 1
  • 11
  • 21