View Single Post
Old 11-10-2011, 04:04 PM   #5
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 11,741
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by smoothrolla View Post
Thanks Charley!
chaley, not charley.
Quote:
But this bit of that code adds tags in lowercase:
Code:
for item in l1lcase:
        for item2 in l2:
            if item2 in item:
                res.add(item2)
                break
That is the point of the 'enumerate'. The arrays l1 and l1lcase are ordered and indexed the same, so
Code:
for idx,item in enumerate(l1lcase):
        for item2 in l2:
            if item2 in item:
                res.add(l1[idx])
                break
will add the cased version of item2 to the result.

The enumerate operator returns the index and the value (a tuple in python terms), which in this case is the index and the lowercase version of the value. Because l1lcase and l1 are parallel arrays, the l1[idx] gets the equivalent item for the one in l1lcase, which is the cased version.
chaley is offline   Reply With Quote