python - Combining two lists into one list where they share the same values and removing duplicates using list comprehensions -


i trying combine 2 lists: 1 holds square numbers. other stores pentagonal numbers.

def pentasquares():     l = []     n = 0     squares = lambda x: [x*x x in  range(n)]     penta = lambda y: [y*(3*y-1)//2 y in range(n)]     while l.index < 4:         l = [i in squares j in penta if squares == penta]         n = n+1     return l 

i must merge these lists using list comprehensions values match until there 4 elements in list.

if point me in right direction, appreciated.

i getting error: typeerror: unorderable types: builtin_function_or_method() < int()

def pentasquares(n):     squarlist=[x*x x in range(n)]     pentalist=[y * (3*y-1) // 2 y in range(n)]     l=[x x in squarlist if x in pentalist]     return l  >>> pentasquares(10000) [0, 1, 9801, 94109401] 

edit 1 o.p satisfaction

def pentasquares(n):     squarlist=[]     pentalist=[]     squares = lambda x:x*x     penta = lambda y:y*(3*y-1)//2     in range(n):         squarlist.append(squares(i))         pentalist.append(penta(i))     l=[x x in squarlist if x in pentalist]     if l < 4:         print('there less 4 values, input larger n')     return l 

Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -