newbie newbie - 4 months ago 20
Python Question

list reverse, list multiple by -1

Expected Result:

>>> createLists(5)
([1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [ -5, -4, -3, -2, -1], [-1, -2, -3, -4, -5])


My code:

# Write a function that returns 4 lists given a postive number.
def createLists(num):
ls = [item for item in range(num)]
return set(ls, ls.reverse(), ls.reverse()*(-1), ls*(-1))


Anybody guide me how to do this?

Answer
def createLists(num): 
    ls = range(1, num+1)
    return (ls, ls[::-1], [-n for n in ls][::-1], [-n for n in ls])

print createLists(5)

http://ideone.com/B0ixx