Andrej Viktorovich wrote:
> Hello,
>
> Trying to understand command:
> [p for p in sys.path]
>
> It prints array of paths. I suppose p becomes array of strings but what []
> means in this statement?
This is called "list comprehension", and
paths = [p for p in sys.path if "foo" in p]
is roughly equivalent to
paths = []
for p in sys.path:
if "foo" in p:
paths.append(p)
Your original example
> [p for p in sys.path]
just copies the items from sys.path into a new list. This is usually done
with the more concise
list(sys.path)
--
https://mail.python.org/mailman/listinfo/python-list