Re: [Tutor] Removing values from a dictionary if they are present in a list

2011-04-01 Thread Peter Otten
Steven D'Aprano wrote: > b = set(B) > for key, values in A.items(): > A[key] = list( set(values).difference(b) ) > > > For Python 3, you will need to change the call A.items() to > list(A.items()), but otherwise they should be the same. The documentation doesn't say so explicitly, see http

Re: [Tutor] Removing values from a dictionary if they are present in a list

2011-04-01 Thread Steven D'Aprano
ranjan das wrote: I have the following information A={'g2': [4,5,3], 'g1': [1, 3]} B=[2,3,5] Now I want to remeove the elements in B if they are present (as values) in dictionary A. My expected solution is A= {'g2': [4], 'g1': [1] } Do you care about the order of the elements in A's value

Re: [Tutor] Removing values from a dictionary if they are present in a list

2011-04-01 Thread Andre Engels
On Fri, Apr 1, 2011 at 9:52 AM, ranjan das wrote: > I have the following information > > A={'g2': [4,5,3], 'g1': [1, 3]} > > B=[2,3,5] > > Now I want to remeove the elements in B if they are present (as values) in > dictionary A. > > My expected solution is > > A= {'g2': [4], 'g1': [1] } > > I wro

Re: [Tutor] Removing values from a dictionary if they are present in a list

2011-04-01 Thread Peter Otten
ranjan das wrote: > I have the following information > > A={'g2': [4,5,3], 'g1': [1, 3]} > > B=[2,3,5] > > Now I want to remeove the elements in B if they are present (as values) in > dictionary A. > > My expected solution is > > A= {'g2': [4], 'g1': [1] } > > I wrote the following piece of

[Tutor] Removing values from a dictionary if they are present in a list

2011-04-01 Thread ranjan das
I have the following information A={'g2': [4,5,3], 'g1': [1, 3]} B=[2,3,5] Now I want to remeove the elements in B if they are present (as values) in dictionary A. My expected solution is A= {'g2': [4], 'g1': [1] } I wrote the following piece of code which gives me thhe right code, but I am s