So I have 2 lists of dictionaries I would like to merge:
posix_groups=[dict(name='group_A', gid=8888881, sid=None),
dict(name='group_B', gid=8888882, sid=None),
dict(name='group_C', gid=8888883, sid=None)]
windows_groups=[dict(name='group_A', gid=8888881, sid='S-1-5-21-927172180-3694312366-24219317-65317'),
dict(name='group_B', gid=None, sid='S-1-5-21-927172180-3694312366-24219317-65318'),
dict(name='group_C', gid=None, sid='S-1-5-21-927172180-3694312366-24219317-65319'),
dict(name='group_Z', gid=6666666, sid='S-1-5-21-927172180-3694312366-24219317-76207')]
Desired output is as follows:
merged_groups=[dict(name='group_A', gid=8888881, sid='S-1-5-21-927172180-3694312366-24219317-65317'),
dict(name='group_B', gid=8888882, sid='S-1-5-21-927172180-3694312366-24219317-65318'),
dict(name='group_C', gid=8888883, sid='S-1-5-21-927172180-3694312366-24219317-65319'),
dict(name='group_Z', gid=6666666, sid='S-1-5-21-927172180-3694312366-24219317-76207')]
Is there elegant (pythonic) way to do it?
Thanks!
question from:
https://stackoverflow.com/questions/65882602/how-to-merge-2-lists-of-dictionaries-so-keys-with-none-values-will-be-always-rep 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…