0
src = max(gameinfo.my_planets.values(), key=lambda p: p.num_ships)
dest = min(gameinfo.not_my_planets.values(), key=lambda p:p.num_ships)

if len(gameinfo.my_fleets) > 0:

for fleet in gameinfo.my_fleets.values(): 
    print fleet.dest.id
    self.dests.append(fleet.dest)

    for i, value in self.dests:
        print value.id
        while value == dest:
           self.dests[i] = choice(gameinfo.enemy_planets.values())

    for i, fleet in gameinfo.my_fleets.values(): 
        gamefleet.fleet_order(fleet, self.dests[i], int(fleet.num_ships))


    # clear for now
    self.dests = []
    return

Problem is the last 2 for loops not sure what to do exactly... getting a 'not iterable' error. The logic is right but just not sure if i have a keyword wrong or something. Been on this all nighttttt!

juliomalegria
  • 24,229
  • 14
  • 73
  • 89
George Veron
  • 35
  • 1
  • 6
  • 1
    You do realize that the indentation after your `if` statement is wrong. I assume that's because of the formatting of the question? And you're using `return` outside of a function. You probably need to post all your code. – alan May 26 '12 at 14:28
  • What is `self.dests`? For your 1st loop to work, it should be an utterable (e.g., list) of tuples. Or, you've forgotten to use `enumerate`. – Helgi May 26 '12 at 14:29
  • The formatting may be off here i copied it wrong but in my IDE (Visual Studio) its perfect. And self.dests is a list in __init__ – George Veron May 26 '12 at 14:30
  • sorry if posts are a mess never used stackoverflow before – George Veron May 26 '12 at 14:31
  • You can edit the question, fix the formatting, and post the rest of your code. – alan May 26 '12 at 14:31

2 Answers2

0

For this to work, self.dests and gameinfo.my_fleets.values() need to be - or need to return - what are called python iterables, objects like strings and lists that you can iterate over (presumably lists of size-2 tuples in this case, looking at your code). Unfortunately these two are not - or are not returning - iterable objects. So you must look into why they aren't, or whether you are at all supposed to iterate over them.

The following is a stack overflow question that discusses how you can identify whether a variable in your program is an iterable object. It should be of some help here:

Community
  • 1
  • 1
Abhranil Das
  • 5,702
  • 6
  • 35
  • 42
  • def __init__(self): # stores destinations self.dests = [] that is where self.dests is and as for gameinfo.my_fleets.values() i am not sure about as that part of the program was not made by myself – George Veron May 26 '12 at 14:38
  • So if you're not sure, use the other question I linked to (that's why I posted it). – Abhranil Das May 26 '12 at 14:42
0

It's hard to say for certain without seeing what kind of values are in self.dests and gameinfo.my_fleets.values(), but I'm guessing that instead of:

for i, value in self.dests:

You really want:

for i, value in enumerate(self.dests):

And similarly for the other for loop.

Edward Loper
  • 15,374
  • 7
  • 43
  • 52
  • It worked for self dest :) !!! but now i need to figure out how to pass self.dest[i] in the next for loop do i need to put a for loop in there aswell? nest in other words? – George Veron May 26 '12 at 14:48
  • It looks like you probably also want to loop `for i, fleet in gameinfo.my_fleets.items()`, instead of `.values()`, assuming `my_fleets` is a dictionary. The "not iterable" problem is probably that it's trying to break up the elements of `my_fleets.values()` into `i` and `fleet`, but that's apparently not possible. – Danica May 26 '12 at 16:06