1.[x for x in data if condition]

此处if主要起条件判断作用,data数据中只有满足if条件的才会被留下,最后统一生成为一个数据列表

2.[exp1 if condition else exp2 for x in data]

此处if...else主要起赋值作用,当data中的数据满足if条件时将其做exp1处理,否则按照exp2处理,最后统一生成为一个 数据列表

 

实例代码:

actual = [i['despensingNum'] for i in res['data'][zy.send.change_data['{{gp}}']] if i['drugName'] == '盐酸多巴胺注射液']

actual = [i['despensingNum'] if i['drugName'] == '盐酸多巴胺注射液' else 0 for i in res['data'][zy.send.change_data['{{gp}}']]]

 

相关文章:

  • 2021-11-29
  • 2022-02-11
  • 2022-12-23
  • 2022-12-23
  • 2021-09-23
  • 2021-06-10
猜你喜欢
  • 2021-11-11
  • 2021-07-03
  • 2021-08-30
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案