1

Could anyone please explain to me why i'm getting a generator instead of a list while running this small test? (When I run it outside a function I get the right values (list))

import math

X = [2,4,9,16,25]

def root(X,method='comp'):
    if method == 'comp':return [math.sqrt(x) for x in X]
    if method == 'map':return list(map(math.sqrt,X)) 
    if method == 'gen':yield (math.sqrt(x) for x in X) 

root(X)
Result:<generator object root at 0x0000018B53883570>

Thanks to you all! :)

David

Wool
  • 138
  • 1
  • 10

0 Answers0