Jan-25-2018, 02:56 PM
Hi,
I am trying to find every other value in a dictionary. This is my thought process:
01) Create a loop to go through the dictionary's index.
02) Use a if statement to run a test with % to see if the result is even or odd
03) If the result is not even then I will append this value to a new list.
Here is the code (just trying to see it print before I start appending
TypeError: 'builtin_function_or_method' object is not iterable
I then tried this
TypeError: not all arguments converted during string formatting
So then I tried this (trying to make it simpler)
TypeError: unsupported operand type(s) for %: 'builtin_function_or_method' and 'int'
Not sure what i am doing wrong. Is the logic that I wrote in how to solve the problem right? If so what is wrong with my implementation of it?
Thanks.
I am trying to find every other value in a dictionary. This is my thought process:
01) Create a loop to go through the dictionary's index.
02) Use a if statement to run a test with % to see if the result is even or odd
03) If the result is not even then I will append this value to a new list.
Here is the code (just trying to see it print before I start appending
odd = () for a in (letlist.index): if ((a % 2) != 0): print (a)Returned: for a in (letlist.index):
TypeError: 'builtin_function_or_method' object is not iterable
I then tried this
odd = () for a in (letlist): if ((a % 2) != 0): print (a)Returned: if ((a % 2) != 0):
TypeError: not all arguments converted during string formatting
So then I tried this (trying to make it simpler)
odd = () for a in (letlist): a = letlist.index if (a % 2): print (a)That returned: if (a % 2):
TypeError: unsupported operand type(s) for %: 'builtin_function_or_method' and 'int'
Not sure what i am doing wrong. Is the logic that I wrote in how to solve the problem right? If so what is wrong with my implementation of it?
Thanks.