Re: comparing values in two sets

2006-05-15 Thread Gerard Flanagan
Gerard Flanagan wrote: > John Salerno wrote: > > I'd like to compare the values in two different sets to test if any of > > the positions in either set share the same value (e.g., if the third > > element of each set is an 'a', then the test fails). > > > > I have this: > > > > def test_sets(origi

Re: comparing values in two sets

2006-05-15 Thread Gerard Flanagan
John Salerno wrote: > I'd like to compare the values in two different sets to test if any of > the positions in either set share the same value (e.g., if the third > element of each set is an 'a', then the test fails). > > I have this: > > def test_sets(original_set, trans_letters): > for pair

Re: comparing values in two sets

2006-05-15 Thread Paul Rubin
Peter Otten <[EMAIL PROTECTED]> writes: > Here's a variant that does performs only the necessary tests: > > >>> from itertools import izip > >>> True not in (a == b for a, b in izip(range(3), range(3))) Cute! -- http://mail.python.org/mailman/listinfo/python-list

Re: comparing values in two sets

2006-05-14 Thread Peter Otten
Paul Rubin wrote: > You could even get cutesy and say something like (untested): > > from itertools import izip > def test_sets(original_set, trans_letters): > return not sum(a==b for a,b in izip(original_set, trans_letters)) > > but that can be slower since it always scans both lists in ent

Re: comparing values in two sets

2006-05-14 Thread John Salerno
John Salerno wrote: > I'd like to compare the values in two different sets Oops, I guess I was a little too loose in my use of the word 'set'. I'm using sets in my program, but by this point they actually become strings, so I'm really comparing strings. Thanks for pointing that out to me, and

Re: comparing values in two sets

2006-05-14 Thread Paul Rubin
John Salerno <[EMAIL PROTECTED]> writes: > I'd like to compare the values in two different sets to test if any of > the positions in either set share the same value (e.g., if the third > element of each set is an 'a', then the test fails). I think by "sets" you mean "lists". Sets are unordered, a

Re: comparing values in two sets

2006-05-14 Thread Tim Chase
> I'd like to compare the values in two different sets to > test if any of the positions in either set share the same > value (e.g., if the third element of each set is an 'a', > then the test fails). There's an inherant problem with this...sets by definition are unordered, much like dictionaries.

Re: comparing values in two sets

2006-05-14 Thread John Machin
John Salerno wrote: > I'd like to compare the values in two different sets to test if any of > the positions in either set share the same value (e.g., if the third > element of each set is an 'a', then the test fails). > > I have this: > > def test_sets(original_set, trans_letters): > for pair

Re: comparing values in two sets

2006-05-14 Thread bearophileHUGS
So you probably have to change the function test_sets name, because it's not much useful on real sets. Can't you use the == or != operators on those sequences? Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: comparing values in two sets

2006-05-14 Thread bearophileHUGS
Note that you are comparing ordered sequences, like lists, tuples, strings, etc, and not sets. Something like this can be a little improvement of your code, it avoids building the zipped list, and scans the iterable unpacking it on the fly: from itertools import izip def test_sets(original_set, tr

Re: comparing values in two sets

2006-05-14 Thread skip
John> I'd like to compare the values in two different sets to test if John> any of the positions in either set share the same value (e.g., if John> the third element of each set is an 'a', then the test fails). Do you really mean "set" and not "list"? Note that they are unordered. Th

comparing values in two sets

2006-05-14 Thread John Salerno
I'd like to compare the values in two different sets to test if any of the positions in either set share the same value (e.g., if the third element of each set is an 'a', then the test fails). I have this: def test_sets(original_set, trans_letters): for pair in zip(original_set, trans_lett