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
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
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
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
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
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
> 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.
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
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
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
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
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
12 matches
Mail list logo