0

I have data like:

[{'_id': ObjectId('6437a7deab4ab82dfa6ac44f'),
  'code': 'HK.HSI230427C20200000',
  'volume': 444.0,
  'ask': 374.0,
  'bid': 371.0,
  'ask_vol': 2.0,
  'bid_vol': 9.0,
  'OI': 803.0,
  'iv': 23.28,
  'greek': {'delta': 0.510971123,
   'gamma': 0.000427008,
   'vega': 15.984692646,
   'theta': -12.931898764},
  'when': 1681369054.147017,
  'date': '04-13',
  'hour': '14',
  'isCall': True,
  'underlying': 'HK.800000',
  'strike': 20200.0,
  'DTE': '2023-04-27',
  'stk': '恒生指数'}]

I want to use a list comprehention to filter the 'DTE' data as:

op_chain_DTE = [i['DTE'] for i in option_list]
op_chain_DTE = list(set(op_chain_DTE)) 

Think about the quantity of data is over 1 million, the var 'op_chain_DTE' will be a huge list with lots of duplicated strings. Thus, I try to filter the repeated items into the list at first place as:

op_chain_DTE = [i['DTE'] for i in option_list if i['DTE'] not in self]

Obviously it doesn't work because the list comprehension doesn't have an attribute named "self", it seems the only way will be define a function to do the job.

How can I solve it without writing a function?

mkrieger1
  • 19,194
  • 5
  • 54
  • 65

0 Answers0