i am a newbie in python and facing issue in getting this output
a = [('textVerify', 'AH', 'SELECT SERVICES'), ('textVerify', 'F7', 'test1>'),('audioVerify', '091;0'), ('imageVerify', 'duck.gif'),('imageVerify', 'egg.gif')]
i want to create a new list which should hold all the 0th unique element like
audioVerify,imageVerify,textVerify
so the result expected is
['textVerify',(('AH', 'SELECT SERVICES'), ('F7', 'test1>')) 'audioVerify', ('091;0'), ('imageVerify', ('duck.gif','egg.gif')]
You’d better use a
defaultdictfor this:Now you can access its elements by name/index:
If you need to preserve the order of the dictionary keys, you can use an
OrderedDict, together with the.setdefault()method, as described by Ashwini Chaudhary: