Home > Software design >  Does anyone see this expression to get data in python?
Does anyone see this expression to get data in python?

Time:03-14

nums_frames = dataset['n_frames'][()]

Here use [()] to get the data. i don't understand, i haven't seen this kind of usage in python before. if anyone knows that, could you please explain the usage and scenerio?

CodePudding user response:

Since tuples are hashable, they can be used as dict keys. That includes the empty tuple:

d = {
    (): 'a'
}

print(d[()])

This outputs:

a
  • Related