Hello;
I have the following dictionary: - d={1:[a,b,b], 2:[a,a,b,c], 3:[a,b,c], 4:[a,c]}
I am having trouble removing the duplicate values in each of the keys value list, I need it so that:
[code]d={1:[a,b], 2:[a,b,c], 3:[a,b,c], 4:[a,c]}{/CODE]
I was thinking of that I would need to import the sets module???
4 2062 bvdet 2,851
Expert Mod 2GB
Hello;
I have the following dictionary: - d={1:[a,b,b], 2:[a,a,b,c], 3:[a,b,c], 4:[a,c]}
I am having trouble removing the duplicate values in each of the keys value list, I need it so that:
[code]d={1:[a,b], 2:[a,b,c], 3:[a,b,c], 4:[a,c]}{/CODE]
I was thinking of that I would need to import the sets module???
Are you in Python 2.3? Here is one way of doing it: - dd = {1:['a','b','b'], 2:['a','a','b','c'], 3:['a','b','c'], 4:['a','c']}
-
-
for item in dd.items():
-
# Python 2.3
-
dd[item[0]] = [i for i in item[1] if i not in locals()['_[1]'].__self__]
-
# Python 2.4
-
# dd[item[0]] = [i for i in item[1] if i not in locals()['_[1]']]
-
-
print dd
-
-
# >>> {1: ['a', 'b'], 2: ['a', 'b', 'c'], 3: ['a', 'b', 'c'], 4: ['a', 'c']}
If you are in 2.3, import Set from sets like this: - >>> from sets import Set as set
...and it will seem like you are in 2.4.
Thanks!
I am actually using PythonWin 2.5.1.
Will this cause any problems - I am away from my workstation.
bvdet 2,851
Expert Mod 2GB
Thanks!
I am actually using PythonWin 2.5.1.
Will this cause any problems - I am away from my workstation.
Not that I am aware of. Try the 2.4 version. If that does not work or if you would prefer using set(), use list(set([a,a,b,c])) instead. set() is built-in - no need to import.
2.4 version works great!
Thank you.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Derek Fountain |
last post by:
I'm just starting another PHP project and can see a familiar task not far on
the horizon. I have several database record tuples that I need to
manipulate - person, department, client, job, etc. -...
|
by: Antoon Pardon |
last post by:
Well at least I find them missing.
For the moment I frequently come across the following cases.
1) Two files, each with key-value pairs for the same dictionary.
However it is an error if the...
|
by: superprad |
last post by:
"X-No-Archive: yes"
what I am looking for is
1. To create a list of different words of various lengths(1-15) using
A-Z,a-z,0-9 and punctuations.Basically anything that could be found on
a...
|
by: Rodd Snook |
last post by:
I have an application which makes extensive use of the
Scripting.Dictionary object. I'm not doing anything silly like putting
them outside the page scope -- just creating quite a few of them and...
|
by: shrishjain |
last post by:
Hi All,
I have to make multiple dictionary objects(Dictionary<string key, int
value>) with same set of string keys, and that really eats up lot of
space. I am trying to find a solution where I...
|
by: vatamane |
last post by:
This has been bothering me for a while. Just want to find out if it
just me or perhaps others have thought of this too: Why shouldn't the
keyset of a dictionary be represented as a set instead of a...
|
by: Ben |
last post by:
Hello...
I have set up a dictionary into whose values I am putting a list. I
loop around and around filling my list each time with new values, then
dumping this list into the dictionary. Or so I...
|
by: jerger |
last post by:
I want to help teach to a minority group in Milwaukee, so I want to create a dictionary program that translates a sentence (like a homework problem or teacher instructions), from English into Hmong....
|
by: lazy |
last post by:
Hi,
I have a dictionary something like this,
key1=>{key11=> , key12=> , .... }
For lack of wording, I will call outer dictionary as dict1 and its
value(inner dictionary) dict2 which is a...
|
by: Assimalyst |
last post by:
Hi
I have a Dictionary<string, List<string>>, which i have successfully
filled. My problem is I need to create a filter expression using all
possible permutations of its contents.
i.e. the...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |