[].index
From: Mike Edey (mike_at_edey.mine.nu)
Date: 05/31/04
- Next message: fishboy: "NNTP binary attachment downloader with asyncore and generators"
- Previous message: Zunbeltz Izaola: "Re: exceptions"
- Next in thread: Calvin Spealman: "Re: [].index"
- Reply: Calvin Spealman: "Re: [].index"
- Reply: Jeff Epler: "Re: [].index"
- Reply: Shalabh Chaturvedi: "Re: [].index"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 31 May 2004 14:14:59 GMT
Good day.
Recently I'd run into wishing a list's index method would match
substrings. Being fairly new to this game I can't help but think that my
solution is a little, well, clumsy. In the following trivial example I'm
only interested in finding the first matching list item:
>>> data = ['aaa','bbb','ccc','ddd','eee','fff','ggg','hhh'] foo =
>>> ['b','e','e']
>>> [data[[data.index(iy) for iy in data if iy.find(foo[ix]) > -1][0]] for
>>> ix in range(len(foo))]
['bbb', 'eee', 'eee']
So I guess this question is - have I missed a cleaner method then this
nested list comprehension?
- Next message: fishboy: "NNTP binary attachment downloader with asyncore and generators"
- Previous message: Zunbeltz Izaola: "Re: exceptions"
- Next in thread: Calvin Spealman: "Re: [].index"
- Reply: Calvin Spealman: "Re: [].index"
- Reply: Jeff Epler: "Re: [].index"
- Reply: Shalabh Chaturvedi: "Re: [].index"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|