Skip to main content
added 53 characters in body
Source Link
E. Chan-López
  • 31.3k
  • 3
  • 29
  • 50

Try Cases:

list={94, 35, 47, 29, 86, 40, 46, 72, 87};
List[Cases[listtwolists=List[Cases[list, Except[_?EvenQ]], Cases[list, Except[_?OddQ]]]
(*{{35, 47, 29, 87}, {94, 86, 40, 46, 72}}*)
Map[Median, twolists]
(*{41,72}*)

With order:

List[Sort[Cases[list, Except[_?EvenQ]], Less], Sort[Cases[list, Except[_?OddQ]], Less]]
(*{{29, 35, 47, 87}, {40, 46, 72, 86, 94}}*)
List[Sort[Cases[list, Except[_?EvenQ]], Greater], Sort[Cases[list, Except[_?OddQ]], Greater]]
(*{{87, 47, 35, 29}, {94, 86, 72, 46, 40}}*)

Try Cases:

list={94, 35, 47, 29, 86, 40, 46, 72, 87};
List[Cases[list, Except[_?EvenQ]], Cases[list, Except[_?OddQ]]]
(*{{35, 47, 29, 87}, {94, 86, 40, 46, 72}}*)

With order:

List[Sort[Cases[list, Except[_?EvenQ]], Less], Sort[Cases[list, Except[_?OddQ]], Less]]
(*{{29, 35, 47, 87}, {40, 46, 72, 86, 94}}*)
List[Sort[Cases[list, Except[_?EvenQ]], Greater], Sort[Cases[list, Except[_?OddQ]], Greater]]
(*{{87, 47, 35, 29}, {94, 86, 72, 46, 40}}*)

Try Cases:

list={94, 35, 47, 29, 86, 40, 46, 72, 87};
twolists=List[Cases[list, Except[_?EvenQ]], Cases[list, Except[_?OddQ]]]
(*{{35, 47, 29, 87}, {94, 86, 40, 46, 72}}*)
Map[Median, twolists]
(*{41,72}*)

With order:

List[Sort[Cases[list, Except[_?EvenQ]], Less], Sort[Cases[list, Except[_?OddQ]], Less]]
(*{{29, 35, 47, 87}, {40, 46, 72, 86, 94}}*)
List[Sort[Cases[list, Except[_?EvenQ]], Greater], Sort[Cases[list, Except[_?OddQ]], Greater]]
(*{{87, 47, 35, 29}, {94, 86, 72, 46, 40}}*)
Source Link
E. Chan-López
  • 31.3k
  • 3
  • 29
  • 50

Try Cases:

list={94, 35, 47, 29, 86, 40, 46, 72, 87};
List[Cases[list, Except[_?EvenQ]], Cases[list, Except[_?OddQ]]]
(*{{35, 47, 29, 87}, {94, 86, 40, 46, 72}}*)

With order:

List[Sort[Cases[list, Except[_?EvenQ]], Less], Sort[Cases[list, Except[_?OddQ]], Less]]
(*{{29, 35, 47, 87}, {40, 46, 72, 86, 94}}*)
List[Sort[Cases[list, Except[_?EvenQ]], Greater], Sort[Cases[list, Except[_?OddQ]], Greater]]
(*{{87, 47, 35, 29}, {94, 86, 72, 46, 40}}*)