On Thu, 23 Oct 2014 10:38:53 +0200 Nathann Cohen <nathann.co...@gmail.com> wrote:
> > Ok. To have join(a,b,c,...) or join([a,b,c,...])? > > Hmmm.. Well, we can have both at the same time. Something like that > should do the trick: > > def join(elements, *args): > if args: > args.append(elements) > elements=args > elif elements in self: > elements=[elements] I would personally prefer the following over the above: def foo(*args): if len(args) == 1: elements = args[0] else: elements = args ... do stuff with elements ... This way you can see which case will be used by just looking at the number of arguments and without arguing about the contents of your variables. Also "join" above would throw an exception when a list or other unhashable iterable is used as the only argument: sage: P = Poset() sage: [1,2] in P TypeError: unhashable type: 'list' Also, suppose that I build a poset with elements zero = (), one = (zero,), and two = (zero,one). Then join([zero,one]) and join((zero,one)) would be different, namely with elements=[zero,one] and elements=[two], even though as iterables [one,two] and (one,two) are the same. Regards, Erik Massop -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at http://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.