weixin_46025415
weixin_46025415
采纳率72.7%
2020-08-08 17:09

请问如何删除列表里的空字典?

dd = [{}, {u'attachmentPoint': [{u'switch': u'00:0a', u'port': u'4'}], u'ipv4': [u'10.0.0.3']}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {u'attachmentPoint': [{u'switch': u'00:01', u'port': u'4'}], u'ipv4': [u'10.0.0.1']}, {u'attachmentPoint': [{u'switch': u'00:0b', u'port': u'4'}], u'ipv4': [u'10.0.0.2']}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}]

最后希望

dd=[ {u'Point': [{u'switch': u'00:0a', u'port': u'4'}], u'ipv4': [u'10.0.0.3']},  {u'Point': [{u'switch': u'00:01', u'port': u'4'}], u'ipv4': [u'10.0.0.1']}, {u'Point': [{u'switch': u'00:0b', u'port': u'4'}], u'ipv4': [u'10.0.0.2']}]

请问该怎么做?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

2条回答

  • caozhy 从今以后生命中的每一秒都属于我爱的人 9月前
    dd1 = []
    for x in dd:
      if bool(x):
        dd1.append(x)
    print(dd1)
    
    点赞 1 评论 复制链接分享
  • jingluan666 jingluan666 9月前
    while {} in dd:
        dd.remove({})
    
    点赞 1 评论 复制链接分享

相关推荐