Generate list of numbers and their negative counterparts in Python

Solution 1:

I am unsure if order matters, but you could create a tuple and unpack it in a list comprehension.

nums = [y for x in range(6,10) for y in (x,-x)]
print(nums)
[6, -6, 7, -7, 8, -8, 9, -9]

Solution 2:

Create a nice and readable function:

def range_with_negatives(start, end):
    for x in range(start, end):
        yield x
        yield -x

Usage:

list(range_with_negatives(6, 10))

That is how you get a convenient one-liner for anything. Avoid trying to look like a magic pro hacker.