MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: list equation


Am 06.10.2011 10:38, schrieb dimitris:
> Hello to all.
> 
> Let
> 
> lst = Tuples[Range[100], 2];
> 
> In the previous list appear elements such us {x,y} and {y,x}. (e.g.
> {3,4} and {4,3}).
> I want to create a new list with {y,x} dropped (that is, in the new
> list appears only {3,4}
> and not {4,3}).
> 
> I use
> 
> lstnew = Union[lst, SameTest -> (#1 == Reverse[#2] &)]
> 
> However it is needed almost 150 sec for this procedure ($Version->5.2
> for Windows)
> I know that my laptop is too old but I guess there is a more efficient
> way to
> create lstnew.
> 
> Any ideas?
> 
> Thanks a lot
> 
> Dimitris
> 

lstnew = Subsets[Range[100], {2}];

or if you need lst for other purposes:

lstnew = Union[Sort /@ lst];

hth,
Peter




  • Prev by Date: Re: list equation
  • Next by Date: Re: list equation
  • Previous by thread: Re: list equation
  • Next by thread: Re: list equation