User avatar
PeterO
Posts: 4942
Joined: Sun Jul 22, 2012 4:14 pm

What is this called ?

Mon Mar 05, 2018 1:54 pm

I've found some Python code that I don't know how to describe the construct it uses.
How do you describe the last line in the code below ?

Code: Select all

from lxml import etree 
tree = etree.parse("./glade/eatenMeals.glade")
root = tree.getroot()
               
objects = [itm for itm in root if itm.tag == "object"]
I'm sure there is a name for this "construct" but I don't know what it is.
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

User avatar
LetHopeItsSnowing
Posts: 357
Joined: Sat May 26, 2012 6:40 am
Location: UK
Contact: Website

Re: What is this called ?

Mon Mar 05, 2018 2:00 pm

I call it "list comprehension".
"am I getting slower, or is stuff more complicated; either way I now have to write it down - stuffaboutcode.com"

User avatar
PeterO
Posts: 4942
Joined: Sun Jul 22, 2012 4:14 pm

Re: What is this called ?

Mon Mar 05, 2018 2:12 pm

LetHopeItsSnowing wrote:
Mon Mar 05, 2018 2:00 pm
I call it "list comprehension".
That's it :D It's one of those things that I just hadn't put the "construct" and its proper name together before :o
Now I can go and Google all about list comprehensions 8-)
Thanks
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

Return to “Python”