switch recipe?
Mark McEahern
marklists at mceahern.com
Tue Jul 16 08:46:19 EDT 2002
[Alex Martelli]
> I'm not sure what an lcd is in this context, but I did mean to
> loop least-common-multiple(m, n) times, treating the two sets
> as equivalent. So I guess I had misunderstood the specs!
I seem to have a penchant for maligning concepts. Thanks for the correction
on denominator --> multiple. Would it make sense to say lcd (least common
denominator) is a conceptual subset of lcm (least common multiple)? If so,
that explains my confusion.
I like your 2.3 version, especially making it handle empty setn:
> def weave(setn, setm):
> """Return an iterator that iterates over iterator setn and
> sequence setm until setn is exhausted. If setn is larger than
> setm, cycle over setm."""
> m = len(setm)
> if not m:
> raise ValueError, "Set to be cycled on cannot be empty"
> for index, item in enumerate(setn):
> yield item, setm[index%m]
I posted a summary of all the code presented in this thread here:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/139210
Thanks!
// mark
-
More information about the Python-list
mailing list