list index()

Alex Martelli aleax at mac.com
Fri Aug 31 11:56:21 EDT 2007


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.


Alex



More information about the Python-list mailing list