Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems with list comprehensions #57

Open
nemoyatpeace opened this issue Feb 7, 2015 · 1 comment
Open

Problems with list comprehensions #57

nemoyatpeace opened this issue Feb 7, 2015 · 1 comment
Labels

Comments

@nemoyatpeace
Copy link

I was attempting these lines of code:

        self.say(len(coins))
        bottom = [i for i in coins if i.pos.y <= 51-(13/17)*abs(i.pos.x-60)] 
        coins = [i for i in bottom if i.pos.x>self.pos.x]
        self.say(len(coins))

the first self.say worked fine, the second was broken.

I tried breaking both of the comprehensions into simple for loops and it worked fine:

        bottom = []
        for i in coins:
            if i.pos.y <= 51-(13/17)*abs(i.pos.x-60):
                bottom.append(i)
        coins = []
        for i in bottom:
            if i.pos.x>self.pos.x:
                coins.append(i)

When I tried it with the first comprehension and the second as a loop I got an error on i.pos.x complaining the null doesn't have a .pos.

        bottom = [i for i in coins if i.pos.y <= 51-(13/17)*abs(i.pos.x-60)] 
        coins = []
        for i in bottom:
            if i.pos.x>self.pos.x:
                coins.append(i)

I tried the other direction with the bottom as a list and the coins as a comprehension:

        bottom = []
        for i in coins:
            if i.pos.y <= 51-(13/17)*abs(i.pos.x-60):
                bottom.append(i)
        coins = [i for i in bottom if i.pos.x>self.pos.x]

And it worked. So apparently the issue is in the first comprehension.

@nwinter
Copy link
Collaborator

nwinter commented May 23, 2016

I'm going to guess that this is the same as the other bug with reusing list comprehension variable names: codecombat/aether#133

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants