0

I have a loop, it should trigger on the first if, but it doesn't.

If I print the values

print("Books: {0} {1} {2} {3}".format(book['bookid'], allbooks['bookid'], book['Author'], allbooks['Author']))

I get: Books: 0001 0001 AJHartley AJHartley

I've tried:

if book['bookid'] in allbooks['bookid'] and book['Author'] in allbooks['Author']:
    book_exists += 1

if book['bookid'] == allbooks['bookid'] and book['Author'] == allbooks['Author']:
    book_exists += 1

The only way I can get a match is if I have

if "0001" in book['bookid'] and "AJHartley" in allbooks['Author']:
book_exists += 1

But I'd like to compare two dictionary key values.

John
  • 787
  • 4
  • 11
  • 28
  • Your problem is unclear. Do you want to check dictionnaries intersection? look at [this thread](http://stackoverflow.com/questions/18554012/intersecting-two-dictionaries-in-python#18554081) – mquantin Jan 27 '17 at 11:19
  • I have a dictionary of dictionaries. Each sub dictionary contains library book references. So when entering a new book I want to check if it already exists in the library. So if the book id and book author already exist i'll just increase the book_exists count instead of entering in all the details again. – John Jan 27 '17 at 11:32
  • The exact form of your data structure is unclear, and this is because you did not provide a [Minimal, Complete, and Verifiable](http://stackoverflow.com/help/mcve) example. Thus there is little way to give concrete advice. – Stephen Rauch Jan 27 '17 at 16:36

0 Answers0