0

Possible Duplicate:
strange while statement behaviour?

Given the following, how may I implement list comprehension correctly, exit the loop & run the statements after 'else'? I had tried to scan for '-' characters but it does not work.

Have tried:

while(current != randomValue) 

Trying now:

randomKey = random.choice(list(topic.keys())) randomValue = random.choice(topic[randomKey]) current = "-" * len(randomValue) while (i for i in range (0, len(current)) if i != "-"): (statements) else: (statements) 
2
  • hi :) i tried a workaround since i need my prev post to work so badly. Same issue & person by the way :) Sorry. Commented Nov 3, 2012 at 19:36
  • anw many thanks i tried something else & it worked. A simple solution after so long. Stupid me. Commented Nov 3, 2012 at 19:37

2 Answers 2

0

Your test doesn't make sense -- Bool on a generator is always True:

>>> a = (i for i in range(10)) >>> bool(a) True 

Also i will never == '-' since you're looping over range. I'm not really sure what you're trying here, but we really can't help you solve this unless we see you can manage to boil your actual code down to the minimum important portion. (And who knows, by doing that, you might find the problem yourself)

Sign up to request clarification or add additional context in comments.

1 Comment

anw many thanks i tried something else & it worked. A simple solution after so long. Stupid me.
0

Instead of list comprehension, struggling to make the while statement false etc... I did this, which worked in a way:

while ("-" in current ): 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.