Up to this point in time, in Python, I've only ever seen list comprehensions that specify the inclusion of one element at time. For example, they're all in the following form
[f(x) for x in <iterable>]
Is there any way to specify more than one element at a time? For example,
[f(x), g(x) for x in <iterable>]
I'm asking because I want to create a list comprehension that calculates all the divisors of some number x, but I want to do this as efficiently as possible. Right now I'm using the following,
[y for y in range(1,x+1) if x%y == 0]
but I'd like to do something like this,
[y, x/y for y in range(1, sqrt(x)+1) if x%y == 0]
as this would be more efficient. Btw, I have no practical reason for doing this. It's simply a challenge problem that somebody told me and the goal is to do it with the smallest, most efficient list comprehension possible.
Thanks in advance.
Edit: Ok, it looks like I have to use tuples. I was trying to avoid that though as I'd then have to make another function to flatten the list which would make my solution longer.
Edit 2: Just in case anyone stumbles upon this question, the answer to what I wanted to do in my original question is this:
[y for x in <iterable> for y in f(x), g(x)]
It uses nested for loops in the list comprehension to get the job done.