My question is different from the one asked here. Primarily I am asking what improvements could be made to code containing dictionaries. However, the link explains about memory profilers, which will be my next step.
I have the following two sets of code to achieve the same thing.
First one,
a={1: 'a', 2: 'b', 3: 'c', 4: 'd'}
b=[x for x in a if x in (1,2,3)]
b=['a', 'b', 'c']
Second one,
a={1: 'a', 2: 'b', 3: 'c', 4: 'd'}
c=[a[x] for x in set(a.keys()) & set([1,2,3])]
b=['a', 'b', 'c']
I would like to know which one works better in terms of memory optimized methods, and for large sets of data.
Thanks in advance!