Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9199481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:32:42+00:00 2026-06-17T22:32:42+00:00

I’ve searched around and tried to .encode(…) the string, but I can’t imagine this

  • 0

I’ve searched around and tried to .encode(…) the string, but I can’t imagine this issues is as serious as it seems.

I have two datastructures, one is loaded from a YAML file, the other from a JSON file.

Both contents have been processed (I’m iterating over the data):

Dictionary of YAML

[{'SynID': 66, 'action': 'userInit', 'appLocation': 0},
 {'SynID': 66, 'action': 'isEngager', 'appLocation': 0}]

Dictionary of JSON

{u'name': u'SynID', u'value': u'66'}
...
{u'name': u'action', u'value': u'isEngager'}

Finally, when doing the comparision, anything involving an integer (non string) fails. For example:

    if uriDict['name'] in expectedResultsSubDict and uriDict['value'] == expectedResultsSubDict[uriDict['name']]:
                Logger().l("[%s] Match: %s:%s == %s" % (pos, uriDict['name'], uriDict['value'], expectedResultsSubDict[uriDict['name']]))
    elif uriDict['name'] in expectedResultsSubDict:
         Logger().l("[%s] Name: %s, value: %s" % (pos, uriDict['name'], uriDict['value']))

The first if statement fails to match the key/value of SynID:66, but will match the second entry, action:isEngager.

2013-01-28 12:48:42,151 : DEBUG : [0] Name: SynID, value: 66
2013-01-28 12:48:42,151 : DEBUG : [0] Match: action:userInit == userInit

As you can see in the output, it doesn’t match the SynID, but matches the action.

If I add in this line:

elif uriDict['name'] in expectedResultsSubDict and int(uriDict['value']) == int(expectedResultsSubDict[uriDict['name']]):
    Logger().l("[%s] Int Match: %s:%s == %s" % (pos, uriDict['name'], uriDict['value'], expectedResultsSubDict[uriDict['name']]))

It will work properly on the SynID (and other field that have ints) but fail on the string fields.
I also tried changing the ‘==’ comparison to ‘is’, and in that case, nothing matched.

Q) How do I compare the values of my dictionary?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T22:32:43+00:00Added an answer on June 17, 2026 at 10:32 pm

    You’re comparing 66 to ’66’, which are not equal – one is an int and one is a string. Python does no implicit conversions between types, owing to its philosophy of ‘explicit is better than implicit’ . To get it to work, I’d convert both to string first and then compare, like so

    if uriDict['name'] in expectedResultsSubDict and str(uriDict['value']) == str(expectedResultsSubDict[uriDict['name']]):
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
This could be a duplicate question, but I have no idea what search terms
Does anyone know how can I replace this 2 symbol below from the string
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.