dimanche 26 mai 2019

Discard some dictionaty items in list during random.choice

I want to get random item from a list, also I don't want some items to be consider while random.choice(). Below is my data structure

x=[
  { 'id': 1, 'version':0.1, 'ready': True  }
  { 'id': 6, 'version':0.2, 'ready': True }
  { 'id': 4, 'version':0.1, 'ready': False }
  { 'id': 35, 'version':0.1, 'ready': False  }
  { 'id': 45, 'version':0.1, 'ready': False  }
  { 'id': 63, 'version':0.1, 'ready': True   }
  { 'id': 34, 'version':0.1, 'ready': True   }
  { 'id': 33, 'version':0.1, 'ready': True   }
]

I can get the random item by using random.choice(x). But is there any way, consider 'ready': True attribute of item while random.choice().

Or any SIMPLE trick to achieve this?

NOTE: I want to use python in-built modules to avoid dependencies like numpy, etc.




Aucun commentaire:

Enregistrer un commentaire