By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,948 Members | 838 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,948 IT Pros & Developers. It's quick & easy.

Trying to test whether the index of a dictionary is even or odd

P: 2
Hello everyone,
First time poster. Been at python about 2 weeks now.

As part of a larger challenge (that I have mostly solved) I need to print every other keypair in a dictionary.

The way I thought about this was looping through the dictionary with an index method and then trying to use % to tell if it was even or odd. If it was odd I would just append it to a new variable.

I am having all kind of issues and getting cryptic error messages.

Here is the snippet I am playing around with, right now just trying to get the index to compare and make sure that works before I loop through the dictionary:

Expand|Select|Wrap|Line Numbers
  1. for a in letlist:
  2.     a = (letlist.index)
  3.     int(a)
  4.     if ((a % 2) != 0):
  5.         print (a)
This is the error: TypeError: int() argument must be a string, a bytes-like object or a number, not 'builtin_function_or_method'

I have tried several different permutations and get errors on all. It is almost as if I can't do anything with a because I used it somewhere else.

Any help appreciated
Jan 24 '18 #1
Share this Question
Share on Google+
2 Replies

P: 2
I solved it thanks anyway.
Jan 25 '18 #2

P: 1
Hey, it's really good to hear that you've solved your issue by your own. Great!
Jan 31 '18 #3

Post your reply

Sign in to post your reply or Sign up for a free account.