473,383 Members | 1,877 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

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

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)
  6.  
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
2 2304
fad3r
2
I solved it thanks anyway.
Jan 25 '18 #2
Hey, it's really good to hear that you've solved your issue by your own. Great!
Jan 31 '18 #3

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

Similar topics

17
by: Matt | last post by:
Give a one-line C expression to test whether a number is a power of 2. No loops allowed.
24
by: John Smith | last post by:
How to test whether strstr() returns a null pointer or not? Do I use something like the following? if(NULL != strstr(str1,str2)) That does not seem to work.
5
by: Fabian Steiner | last post by:
Hello! As the subject says I need to test whether a host computer in our network is reachable or not. At the moment I simply attempt to connect to a given port that is open when the machine is...
20
by: ravi | last post by:
Give a one-line C expression to test whether a number is a power of 2.
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
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,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.