Lists. Java vs Python.

1 AM May 16, 2006

Java


public List getImageItems() {
    List result = new ArrayList();
    for (Iterator iter = items.iterator(); iter.hasNext();) {
        ReportItem item = (ReportItem) iter.next();
        if (item instanceof ReportImageItem) {
            result.add(item);
         }
     }
    return result;
}

Python:


@property
def imageItems(self):
    return [i for i in self.items if isinstance(i, ReportImageItem)]

I’m just saying. And, no, I’m not putting this on Javablogs.

By alang | # | Comments (15)
(Posted to Python, Java and Rants)
© 2003-2006 Alan Green