fff
fff

Reputation: 111

get a list in a function in python

I have a function in python like this

def lemmma(file):
    for i in file:
        yield i

This function returns each element in the file

What can I do if I want that the function return a list of elements?

Upvotes: 0

Views: 51

Answers (1)

Ahasanul Haque
Ahasanul Haque

Reputation: 11134

def lemmma(file):
    lst=[]
    for i in file:
        lst.append(i)
    return lst

Or even better,

def lemmma(file):
    return [i for i in file]

Or,

def lemma(file):
    return list(file)

Upvotes: 2

Related Questions