On May 20, 11:08 am, Paul Hankin <[EMAIL PROTECTED]> wrote: > On May 20, 3:58 pm, Paul McGuire <[EMAIL PROTECTED]> wrote: > > > def compress(s): > > seen = set() > > return ''.join(c for c in s if c not in seen and (seen.add(c) or > > True)) > > Slightly nicer is to move the set add out of the conditional... > > def compress(s): > seen = set() > return ''.join(seen.add(c) or c for c in s if c not in seen) > > I wouldn't write it this way though :) > > -- > Paul Hankin
Thank you, Paul. I knew I had seen a cleaner version than mine, and I could not remember how it was done. -- Paul -- http://mail.python.org/mailman/listinfo/python-list