Steven D'Aprano <steve+pyt...@pearwood.info> added the comment:

> it returns IndexError (instead of "u") if used in a list comprehension

Works as expected inside a list comprehension:

>>> var = "u2"
>>> [var.strip()[0] for i in range(2)]
['u', 'u']

>>> ["ok" for i in range(2) if var.strip()[0] == "u"]
['ok', 'ok']


I am 99.99% certain that you have a bug in your code, but your code is so 
complicated that it is not obvious at a glance where the bug is. I am strongly 
tempted to just close this as "Works for me" and tell you to come back and 
re-open the bug report when you have isolated the issue to a simpler case, but 
I will resist the temptation for now.

----------
nosy: +steven.daprano

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue46302>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to