[Chicago] any advice is appreciated

Matt Bone thatmattbone at gmail.com
Fri Dec 21 23:13:58 CET 2012


You might be looking for zip().

for regex_thing, element in zip(list1, list2):
    if regex_thing is None:
        pass
    else:
        do_the_stuff_you_wanna_do()

--matt


On Fri, Dec 21, 2012 at 4:05 PM, Daniel Peters <danieltpeters at gmail.com>wrote:

> I'm at my wits end here.  This is a seemingly functional question
>
>
> I've got two lists
>  list1 is a list of compiled regular expression match objects *and
> possibly *None values, culled from the text of an elementtree element
>  list2 is a list of ElementTree elements  (each of which happens to be a
> sibling to the element the regexs were taken from)
> The length and order of the lists mirror each other, meaning, each are X
> long and have the same ordering, since they both come from the same parent.
>
> So, theoretically I should be able to conditionalize some kind of map-like
> operation such that for each index of list2 i can stuff the corresponding
> index from list1 into
> the elements .text method *or* if the value is None (no regexs found),
> the operation continues on maintaining order, simply skipping the None
> values since that node was ill formed anyway.
>
> I've tried list comprehensions, map itself and simply stacking for loops.
> When I can get anything to work at all, i get the last item of the regex
> list (list1) in *all* of the positions of list2.
>
> Any help would be deeply appreciated.
>
> also, thanks jeremy mcmillian.  Clearly I did *not* double down and write
> a parser.  The sysadmin decided to install 2.6 for me, so I have
> elementtree now.  Thanks again.
>
> _______________________________________________
> Chicago mailing list
> Chicago at python.org
> http://mail.python.org/mailman/listinfo/chicago
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/chicago/attachments/20121221/a1459b68/attachment.html>


More information about the Chicago mailing list