list index()

Steve Holden steve at holdenweb.com
Fri Aug 31 20:26:53 CEST 2007


Alex Martelli wrote:
> mensanator at aol.com <mensanator at aol.com> wrote:
>    ...
>> Why wouldn't "the one obvious way" be:
>>
>>  def inAnotB(A, B):
>>      inA  = set(os.listdir(A))
>>      inBs = set(os.listdir(B))
>>      return inA.difference(inBs)
> 
> If you want a set as the result, that's one possibility (although
> possibly a bit wasteful as you're building one more set than necessary);
> I read the original request as implying a sorted list result is wanted,
> just like os.listdir returns (possibly sorted in case-independent order
> depending on the underlying filesystem).  There's no real added value in
> destroying inA's ordering by making it a set, when the list
> comprehension just "naturally keeps" its ordering.
> 
As I had reason to point out in another thread only recently, 
os.listdir() makes no promises about the filename ordering.

Nevertheless I agree with you that the list comprehension method is the 
obvious way to solve the problem, and the set optimization is just that.

regards
  Steve
-- 
Steve Holden        +1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd           http://www.holdenweb.com
Skype: holdenweb      http://del.icio.us/steve.holden
--------------- Asciimercial ------------------
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
----------- Thank You for Reading -------------




More information about the Python-list mailing list