sicarie 4,677
Recognized Expert Moderator Specialist
I'm querying two different systems by username/email and comparing the results, however I'm not incredibly familiar with python and don't know the best way to compare the dictionary entries.
The three quirky things are:
1) The results are returned in a dictionary (from both systems), whose values are a list of user attributes, and I'd like to compare either the username or the email fields in the list inside the dictionary (preferably email as it's required to be unique)
2) The format is 'clean' on one return - ie email@domain.co m but in list form from another, ie ['email2@domain2 .com'] (same with username) - not sure if this matters, it hasn't seemed to yet
3) there may be multiple email addresses. Only one is required to be unique, and one of the dictionaries may have multiple emails (though it is contained to a single source - say source 1's dictionary may have multiples, source 2's does not)
I've tried many things, what I'm looking at now is something like: -
for key, value in data: #source2
-
for k, v in result: # source1 (possibly multiple emails)
-
for entry in value:
-
#this now looks wrong to me, I might not need the for above, but it still doesn't work without...
-
if entry.get("mail",[]) in v.get("mail",[]):
-
print "Match"
-
print value
-
print v
-
# eventually will join additional fields
-
# eventually will write to file
-
else:
-
#doesn't match, skip for now
-
pass
-
4 1365 bvdet 2,851
Recognized Expert Moderator Specialist
Can you post a small representable sample of both data? If data (source 2) is a dictionary, you would need to iterate like this: - for key, value in data.items():
OR - for key in data:
-
value = data[key]
sicarie 4,677
Recognized Expert Moderator Specialist
Yep, I made some changes to it, but didn't want to keep editing my post on the fly. I can access the elements through: -
for key, value in data: #data=list, value=dict(most of the time)
-
if isinstance(value,dict):
-
for k, v in result: # result=list, v=dict(most fo the time)
-
if isinstance(v,dict):
-
if value.get("mail",[]) in v.get("mail",[]):
-
print "Match"
-
print value
-
print v
-
It's getting down to the value.get and v.get, but the if <item1> in <item2>: is not matching, It's a list of strings, but I can't figure out how to and how else I can compare.
Sample data from data:
Key (string) = User,Group (I disregard this except for iteration)
Value (dictionary) = {'mail': ['email@domain.c om'], 'type': ['code'], 'name': ['User Name']}
Sample data from result:
k (string) = User,group (again I generally disregard)
v (dict) = {'mail': ['email@domain.c om','email2@dom ain.com'], 'group': ['group'], 'type': ['code'], 'name': ['User Name']}
And when I iterate through either value or v I get that they are lists, but I can't seem to pull the individual values with what I'm coding. Not sure if that's relevant :)
Edit: I'm correlating two groups together, and I'm trying to find the people that match between the groups, as well as those that are only from source1 or only from source2. The source with multiple emails is the only thing I can guarantee will be unique, which is why I chose that to sort on. I'm definitely open to other types, but I wasn't sure if set differences would catch everything I'm looking for
sicarie 4,677
Recognized Expert Moderator Specialist
I got it, it was a list, so I assigned it to a variable and converted it to a string and the comparison worked
Thanks for the help bvdet!
bvdet 2,851
Recognized Expert Moderator Specialist
Glad you were able to work it out. Thanks for the feedback.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Tim Daneliuk |
last post by:
I am aware that dictionary order is not guaranteed. But I ran into
something puzzling today. I filled a dictionary dynamically as a
program ran. Up to a certain point, the key order was the order
in which things were added. However, at some point, the dictionary
appeared to reorder its contents in some non-deterministic way - in
fact, it...
|
by: brianobush |
last post by:
#
# My problem is that I want to create a
# class, but the variables aren't known
# all at once. So, I use a dictionary to
# store the values in temporarily.
# Then when I have a complete set, I want to
# init a class from that dictionary.
# However, I don't want to specify the
# dictionary gets by hand
# since it is error prone.
|
by: Martin Widmer |
last post by:
Hi Folks.
When I iterate through my custom designed collection, I always get the
error:
"Unable to cast object of type 'System.Collections.DictionaryEntry' to type
'ContentObjects.ContentBlock'."
The error occurs at the "For...Each" line if this method:
|
by: Ilias Lazaridis |
last post by:
remark: not sure if the term "dictionary" is correct here.
I have the following situation:
within a setup.cfg, settings are passed this way:
settings=project_page=theProjectPage.com
myVar=myValue
those are accessible later like this:
|
by: John Henry |
last post by:
Hi list,
I am sure there are many ways of doing comparision but I like to see
what you would do if you have 2 dictionary sets (containing lots of
data - like 20000 keys and each key contains a dozen or so of records)
and you want to build a list of differences about these two sets.
I like to end up with 3 lists: what's in A and not in B,...
| |
by: keleathi |
last post by:
I'm pulling in data from two servers over two SSH tunnels. The tables on each of the servers have the same fields, 8 in total. I need a way to see if an entry that is in the first server is also on the second server. Out of 8 of the fields, 5 will have to match to be considered a match (but I need to pull all 8 in order to use them in the...
|
by: Bob Altman |
last post by:
Hi all,
I'm trying to do something that should be really easy, but I can't think of an
obvious way to do it. I have a dictionary whose value is a "value type" (as
opposed to a reference type -- in this case, a Boolean):
Dim dic As New Dictionary(Of Int32, Boolean)
dic(123) = True
I want to set all of the existing entries in the...
|
by: John Townsend |
last post by:
Joe had a good point! Let me describe what problem I'm trying to solve and the list can recommend some suggestions.
I have two text files. Each file contains data like this:
Test file 1234 4567 8975
I want to compare the numbers in each text file. The data set (i.e. the numbers) has a unique identifier: the "test" + the "file". The text...
|
by: =?Utf-8?B?anAybXNmdA==?= |
last post by:
I'm pulling records from or database by dates, and there are multiple records
for each part number.
The part numbers are being stored as strings in a List in a custom Employee
class:
List<stringParts = new List<string>();
If a part number is not already in the list, a new entry is created for an
employee that gets credited this part...
|
by: plotdevice |
last post by:
I have a text file that has a frequently-changing list of filenames in it.
exampleList.txt:
fee.doc
fye.doc
foe.doc
fum.doc
ftangftang_ole_biscuitbarrel.doc
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |