Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

more pythonic version of list iteration function

Is there a more Pythonic way of defining this function?

def idsToElements(ids):
    elements = []
    for i in ids:
        elements.append(doc.GetElement(i))
    return elements

Maybe its possible with list comprehension. I am basically looking to take a list of ids and change them to a list of elements in something simpler than defining a function.

like image 817
konrad Avatar asked Nov 27 '22 22:11

konrad


1 Answers

If a list comprehension is all that you wanted

def idsToElements(ids):
    return [doc.GetElement(i) for i in ids ]
like image 103
Bhargav Rao Avatar answered Nov 29 '22 14:11

Bhargav Rao