[Question]
  [
Help! My **[Completely Automated Lights From Darks Separator V3001.01](http://i.ebayimg.com/00/s/NTEyWDUxMg==/z/E1MAAOSwr81UPxrD/$_1.JPG)** broke! :(
# Guidelines
---
## Task
Write a program that will take an input of an array (or a list in some languages) of any amount of strings that are either the letter L or the letter D (representing lights or darks) and output an array that contains two arrays, one with all the L's, and one with all the D's.
---
## Rules
* It's code golf so the shortest answer in bytes wins
* Input will only ever contain capitals
* There must be the same number of L's in the output as there is in the input, same goes for the D's
* The input may only have one element (or maybe even *zero* elements)
* If one or both of the output arrays contain no elements, output an empty list (in some languages this may mean you need to output a string)
* Always have the first array be the array of L's
---
## Example output:
`["L","D","L","D","D"] -> [["L","L"],["D","D","D"]]`
`["L","L","L"] -> [["L","L","L"],[]]`
`["D","D"] -> [[],["D","D"]]`
`[] -> [[],[]]`
  
[Answer]
# [Python 3](https://docs.python.org/3/), 37 bytes
```
lambda a:[[c]*a.count(c)for c in"LD"]
```
[Try it online!](https://tio.run/##K6gsycjPM/6fZhvzPycxNyklUSHRKjo6OVYrUS85vzSvRCNZMy2/SCFZITNPycdFKfZ/QVEmUDRNI1rJR0lHyQWIYTRQVlOTC1UeglHFsagFcv4DAA "Python 3 – Try It Online")
[Answer]
# APL, 8 bytes
```
'DL'~⍨¨⊂
```
Explanation:
* `⊂`: enclosed input
* `~⍨¨`: without each
* `'DL'`: 'D' and 'L'
Examples:
```
      ('DL'~⍨¨⊂) 'LDLDD'
┌──┬───┐
│LL│DDD│
└──┴───┘
      ('DL'~⍨¨⊂) 'LLL'
┌───┬┐
│LLL││
└───┴┘
      ('DL'~⍨¨⊂) 'DD'
┌┬──┐
││DD│
└┴──┘
      ('DL'~⍨¨⊂) ''
┌┬┐
│││
└┴┘
```
[Answer]
# [Haskell](https://www.haskell.org/), 28 bytes
```
f l=[filter(==[c])l|c<-"LD"]
```
[Try it online!](https://tio.run/##y0gszk7Nyfn/P00hxzY6LTOnJLVIw9Y2OjlWM6cm2UZXycdFKfZ/iW10tJKPko6SCxDDaKCEDkQUgkE8uHhsLFduYmaegq1CbmKBr4JGQWlJcEmRT55ecUZ@uaaCCkhYIU2h5D8A "Haskell – Try It Online")
If the input can be a list of characters, the `[]` around `c` can be removed.
[Answer]
# PHP, 46 bytes
Assumed given list is:
`$arr = ['L','L','D','D','L','D','D','D','D','L'];`
`foreach($arr as $b){$a[$b][]=$b;};print_r($a);`
[Answer]
# Mathematica, 27 bytes
```
Rest/@Gather[{L,D}~Join~#]&
```
Pure function taking a list of `L`s and `D`s (symbols, not characters/strings) as input and returning a list of two lists. For example,
```
Rest/@Gather[{L,D}~Join~#]& @ {D, L, L, D, L}
```
returns `{{L, L, L}, {D, D}}`. [Try it online!](https://tio.run/##y00sychMLv6fZvs/KLW4RN/BHSiQWhRd7aPjUlvnlZ@ZV6ccq/Y/oCgzryQ6zaHaRUfBB4xAjNrY/wA)
`Gather` by itself is close to what we want, but fails to meet the spec in two ways: it doesn't produce empty lists if the input is missing `L`s or `D`s, and it doesn't always sort `L`s to the left. Replacing the input `#` with `{L,D}~Join~#` solves both problems at once: it means there will be at least one `L` and at least one `D`, and the `L`s will be returned first since an `L` was encountered first. `Rest/@` then removes the initial `L` and `D`.
(I tried a solution using `Count`, but due to currying issues, it didn't seem to be shorter: `±q_:=#~Table~Count[q,#]&/@{L,D}` is 31 bytes.)
[Answer]
## Haskell, 32 bytes
```
import Data.List
partition(>"K")
```
Just a boring library function.
[Try it online!](https://tio.run/##y0gszk7Nyfn/PzO3IL@oRMElsSRRzyezuIQrzbYgsagksyQzP0/DTslbSfN/bmJmnoKtQko@l4JCQVFmXomCikKaQrSSj5KOkgsQw2gXpVgsKiA4VgFNCqoBTTj2PwA "Haskell – Try It Online")
[Answer]
# [Ruby](https://www.ruby-lang.org/), 26 bytes
```
->x{x.partition{|e|e==?L}}
```
[Try it online!](https://tio.run/##KypNqvyfZvtf166iukKvILGoJLMkMz@vuia1JtXW1t6ntvZ/QWlJsUJadLSSj5KOkgsQw2gXpdhYBVtbBaiUj1KsTjRUAiLJhaIVqgZVC1QbUC1CMarZCEORFSHJAoX/AwA "Ruby – Try It Online")
[Answer]
# [Japt](https://github.com/ETHproductions/japt/), ~~13~~ ~~12~~ 10 bytes
```
2Æf¥"LD"gX
```
[Test it](https://ethproductions.github.io/japt/?v=1.4.5&code=MsZmpSJMRCJnWA==&input=WyJMIiwiRCIsIkwiLCJEIiwiRCJdCi1R) (`-Q` flag for visualisation purposes only)
---
## Explanation
Implicit input of array `U`.
```
2Æ
```
Generate the array `[0,1]` and pass each element through a function, with `X` being the current element.
```
f¥
```
Filter `U` by checking for equality...
```
"LD"gX
```
...with the character in string `LD` at index `X`.
[Answer]
# PHP7, ~~52~~ 45 bytes
*-7 bytes thanks to @Jörg Hülsermann*  
```
foreach($argv as$a)$$a[]=$a;print_r([$L,$D]);
```
Use with CLI as `php -r a.php L L L D D L D`
The script goes through the provided arguments and appends them to an array based on its value.
[Answer]
# Common Lisp, ~~66~~ 65 bytes
```
(defun f(x)`(,(remove"D"x :test'equal),(remove"L"x :test'equal)))
```
[Try it online!](https://tio.run/##S87JLC74/18jJTWtNE8hTaNCM0FDR6MoNTe/LFXJRalCwaoktbhEPbWwNDFHEy7hgyahqflfo6AoM69EQSNNQV0DqFEBjH2QaAgGKQUA)
If, instead of strings, we use symbols, then it is much shorter:
# Common Lisp, ~~42~~ ~~41~~ 40 bytes
```
(defun f(x)(mapcar'remove'(D L)`(,x,x)))
```
[Try it online!](https://tio.run/##DclLCsAgDAXAq2SXF/AYLj2EYhWEasV@yO1TmeXks93TDEep76AKFfQ0c1q8Sr@@wvAUJMKpUxExzNXGQ6jECOS3sH/HDw)
```
(f '(D D L L D L D)) ; => ((L L L) (D D D D)) 
```
[Answer]
# [Racket](https://racket-lang.org), 48 bytes
```
(compose list((curry partition)(λ(x)(eq? x'L))))
```
Just apply this anonymous function to, e.g., `'(L D L D D L)`
[Answer]
## Mathematica, ~~22~~ 18 bytes
*4 bytes saved by the genius of CalculatorFeline!*
```
Cases@@@{#|L,#|D}&
```
[Try it online](https://tio.run/##y00sychMLv6fZvvfObE4tdjBwaFaucZHR7nGpVbtf0BRZl6JQ5pDtYuOi44PBNf@BwA "Mathics – Try It Online"), or at the [Wolfram sandbox](https://sandbox.open.wolframcloud.com/)!
Input is a list of the symbols `L` and `D` — not strings, just the letters on their own, like in [Greg Martin's answer](https://codegolf.stackexchange.com/a/131835/66104). The syntax `#|L` is shorthand for `Alternatives[#,L]`, but the `@@@` syntax replaces the head `Alternatives` with `Cases`, so this code is equivalent to `{Cases[#,L],Cases[#,D]}&`.
[Answer]
# [Prolog (SWI)](http://www.swi-prolog.org), 42, 37 bytes
```
l('L').
w(L,D,W):-partition(l,W,L,D).
```
[Try it online!](https://tio.run/##KyjKz8lP1y0uz/z/P0cjQtNKN8JW3Uddj6tcw0fHRSccKFCQWFSSWZKZn6eRoxOuAxTV1Pv/v1zDUcdJJxqoVAeMXeB0rKYeAA "Prolog (SWI) – Try It Online")
Given that `W` is a list of washing, `w/3` will unify `L` and `D` into lists of Lights and Darks respectively, by partitioning the washing against a predicate which succeeds if an item is a Light.
[Edit: golfed -5 thanks to [Fatalize](https://codegolf.stackexchange.com/users/41723/fatalize)]
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), ~~10~~ 9 bytes
```
mc@dQ1"LD
```
[Test suite](http://pyth.herokuapp.com/?code=mc%40dQ1%22LD&test_suite=1&test_suite_input=%5B%22L%22%2C%22D%22%2C%22L%22%2C%22D%22%2C%22D%22%5D%0A%5B%22L%22%2C%22L%22%2C%22L%22%5D%0A%5B%22D%22%2C%22D%22%5D%0A%5B%5D&debug=0).
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 8 bytes
```
'LÃ¹'DÃ)
```
[Try it online!](https://tio.run/##MzBNTDJM/f9f3edw86Gd6i6HmzX//49W8lHSgeJYAA "05AB1E – Try It Online")
[Answer]
# Javascript (ES6), 37 bytes
This is based on a (now deleted) Javascript (ES6) answer.
```
a=>[(b=c=>a.filter(d=>c==d))`L`,b`D`]
```
**Ungolfed version:**
```
function(array) {
  function filter(character){
    return array.filter(function(d) {
      return character == d;
    });
  }
  return [filter("L"), filter("D")];
}
```
**Example code snippet:**
```
f=
a=>[(b=c=>a.filter(d=>c==d))`L`,b`D`]
console.log(f(["L", "D", "L", "D", "D"]))
```
[Answer]
# C#, 61 bytes
```
using System.Linq;a=>new[]{a.Where(c=>c<69),a.Where(c=>c>68)}
```
Full/Formatted Version:
```
using System;
using System.Linq;
class P
{
    static void Main()
    {
        Func<char[], System.Collections.Generic.IEnumerable<char>[]> f =
            a => new[] { a.Where(c => c < 69), a.Where(c => c > 68) };
        Console.WriteLine(string.Join(", ", f(new[]{ 'L', 'D', 'L', 'D', 'D' }).SelectMany(a => a.Select(c => c))));
        Console.ReadLine();
    }
}
```
[Answer]
# [F#](http://fsharp.org/), 37 bytes
```
let f s=List.partition(fun a->a="L")s
```
[Try it online!](https://tio.run/##SyvWzc3Py///Pye1RCFNodjWJ7O4RK8gsagksyQzP08jrTRPIVHXLtFWyUdJs/h/QVFmXklanoKSqqOSgkaaQjRQ2FrJBYhhtItSrCYXdmUQjFUat85Yzf8A "F# (Mono) – Try It Online")
Takes input as a list of strings, and returns two lists, the first with elements where `fun a -> a="L"` is true and the other with elements that result in false.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 10 bytes
```
ẎfÐ€⁾LDW€€
```
[Try it online!](https://tio.run/##y0rNyan8///hrr60wxMeNa151LjPxyUcxGha8/9w@9FJD3fO@P8/Wt1HXUdB3QVEIFgu6rEA "Jelly – Try It Online")
In Jelly a string is a list of 1-char Python strings, e.g. `['a', 'b', 'c']`. That's why you get output such as `[[['L'], ['L']], [['D'], ['D'], ['D']]]`, since 1-char Jelly strings behave the same.
Doesn't work as a full program, hence the `ÇŒṘ` at the bottom.
[Answer]
# [Perse](https://github.com/faso/Perse), 21 bytes
```
part(i,fn(x){x=="L"})
```
I may or may not have implemented the list partition function specifically for this challenge. Takes the input as an array of strings.
[Answer]
# [Husk](https://github.com/barbuz/Husk), 7 bytes
```
Mof-"DL
```
[Try it online!](https://tio.run/##yygtzv6fq1EcrPOoqfG/b36arpKLz////6OjlXyUdJRcgBhGuyjF6kBEIRjEg4vHxgIA "Husk – Try It Online")
### Explanation
```
Mof-"DL
M   "DL    For each character in ['D','L']:
 of-         keep only those strings that are not empty if that character is removed
```
[Answer]
# Java 8, ~~110~~ 106 bytes
```
a->{String[]r={"",""};for(char c:a)r[c/69]+=c;return new char[][]{r[1].toCharArray(),r[0].toCharArray()};}
```
-4 bytes thanks to *@Nevay*.
**Explanation:**
[Try it here.](https://tio.run/##rZBNT8MwDIbv/RVWL01FF@CCBFEnIXaEXcYt6iGkGUtpk8pNh6Yqv71k7cYkrkNKLH/otR@7EnuxsK0yVfk16qa16KAKOdo7XdNnRHHoWCRr0XXwJrQZIgBtnMKtkArWxxBA7gTyghcgyeyCSFmo@PDD65xwWsIaDOQwisVy2DjU5pMXmA9xnMWxZ1uLkxbkk0iRy9uHx@ImlwyV69GAUd@/Uwbk9wV19iXEEyBJM@R3f1Ke@ZHN89v@ow7zTxh7q0towirkTBFo5z02h86phtre0TaUXG3IfAFaKtW@21lADJXkAjQkr0kGyepoLt4q8Wk6HeG6tidzdbN/gjrrfeTHHw)
```
a->{                      // Method with char-array parameter and 2D char-array return-type
  String[]r={"",""};      //  Two Strings in an array
  for(char c:a)           //  Loop over the characters of the input
    r[c/69]+=c;           //   Append either of the two String with the character
                          //   c/69 will result in 0 for 'D' and 1 for 'L'
                          //  End of loop (implicit / single-line body)
  return new char[][]{    //  Return a 2D character-array
    r[1].toCharArray(),   //   With the String for L's converted to a char-array
    r[0].toCharArray()};  //   and String D's converted to a char-array
}                         // End of method
```
[Answer]
# Octave, 21 bytes
```
@(A){A(a=A>72),A(~a)}
```
Input is an array of characters, output is a cell array. Recycled from my answer [here](https://codegolf.stackexchange.com/questions/70779/consolidate-an-array/70827#70827).
Sample execution on [ideone](https://ideone.com/akbaAJ).
[Answer]
# [R](https://www.r-project.org/), 35 bytes
```
x=scan(,'');list(x[i<-x>'D'],x[!i])
```
[Try it online!](https://tio.run/##K/r/v8K2ODkxT0NHXV3TOiezuESjIjrTRrfCTt1FPVanIloxM1bzv4@Cj4ILEILJ/wA "R – Try It Online")
Reads from stdin.
[Answer]
# Julia, 26 bytes
```
g(s)=s[s.=="L"],s[s.=="D"]
```
[Answer]
# [Ruby](https://www.ruby-lang.org/), 20 bytes
```
->l{[l-[?D],l-[?L]]}
```
[Try it online!](https://tio.run/##KypNqvyfZvtf1y6nOjpHN9reJVYHRPnExtb@L1BIi45W8lHSUXIBYhjtohQby4WQgmC4EKoKIP0fAA "Ruby – Try It Online")
[Answer]
# [Thunno 2](https://github.com/Thunno/Thunno2), 8 [bytes](https://github.com/Thunno/Thunno2/blob/main/docs/codepage.md)
```
`LDdẊcx×
```
[Try it online!](https://Not-Thonnu.github.io/run#aGVhZGVyPSZjb2RlPSU2MExEZCVFMSVCQSU4QWN4JUMzJTk3JmZvb3Rlcj1kJmlucHV0PSU1QiUyMkwlMjIlMkMlMjJEJTIyJTJDJTIyTCUyMiUyQyUyMkQlMjIlMkMlMjJEJTIyJTVEJTIwLSUzRSUyMCU1QiU1QiUyMkwlMjIlMkMlMjJMJTIyJTVEJTJDJTVCJTIyRCUyMiUyQyUyMkQlMjIlMkMlMjJEJTIyJTVEJTVEJTBBJTVCJTIyTCUyMiUyQyUyMkwlMjIlMkMlMjJMJTIyJTVEJTIwLSUzRSUyMCU1QiU1QiUyMkwlMjIlMkMlMjJMJTIyJTJDJTIyTCUyMiU1RCUyQyU1QiU1RCU1RCUwQSU1QiUyMkQlMjIlMkMlMjJEJTIyJTVEJTIwLSUzRSUyMCU1QiU1QiU1RCUyQyU1QiUyMkQlMjIlMkMlMjJEJTIyJTVEJTVEJTBBJTVCJTVEJTIwLSUzRSUyMCU1QiU1QiU1RCUyQyU1QiU1RCU1RCZmbGFncz1D)
#### Explanation
```
`LDdẊcx×  # Implicit input                   ->  ["L","D","L","D","D"]
`LD       # Push the string "LD"             ->  ["L","D","L","D","D"]  "LD"
   d      # Split it into characters         ->  ["L","D","L","D","D"]  ["L","D"]
    Ẋ     # Store it in x without popping    ->  ["L","D","L","D","D"]  ["L","D"]
     c    # Count occurrences in the input   ->  [2,3]
      x×  # Multiply by x elementwise        ->  [["L","L"],["D","D","D"]]
          # Implicit output
```
[Answer]
# [Haskell](https://www.haskell.org/) (Lambdabot), 41 bytes
```
reverse.map tail.group.sort.("LD"++).join
```
[Try it online!](https://tio.run/##VY29DoIwGEX3PsWXskCAvgEDAcNSDIsTEtPEotXSNm11MT57rT8MDic3uecm98zclUsZHmUCtN52u7rbQDMMkJRPJBajrYdGK2@1JL1W7LiWLfOMUOE8mqt9sPzOreNkYQY8E5KcrL4Z4uKSpJi2OM8zctFCBc@dd1AhgBFGTHGB28iaLZ6iKX7my9r8@XdMCC1MKKgg3vYHSI0VypM5g89JeAE "Haskell – Try It Online")
[Answer]
# [PowerShell](https://github.com/TryItOnline/TioSetup/wiki/Powershell), 27 bytes
```
($args-eq'L'),($args-eq'D')
```
[Try it online!](https://tio.run/##K8gvTy0qzkjNyfn/X0MlsSi9WDe1UN1HXVMHwXNR1/z//7@Pgo@CCwgDAA "PowerShell – Try It Online")
---
Edit: previously `$args.where({$_-eq'L'},'sp')` for 28 bytes. Could be `$args.where({+"0x$_"},'sp')` for 27 if not for the rule that L's must come first.
[Answer]
# [CJam](https://sourceforge.net/p/cjam), 14 bytes
```
"LD"qf{1$e=*}`
```
Input is a list of characters (string), output is a list of lists of characters (list of strings).
[Try it online!](https://tio.run/##S85KzP3/X8nHRakwrdpQJdVWqzbh/38fIHABAiDp4wIA "CJam – Try It Online")
Explanation:
```
"LD"  e# Push the string "LD"                  | "LD"
q     e# Push the input                        | "LD" "LDLLDLDDL"
f{    e# Foreach char in "LD", push input and: | ['L "LDLLDLDDL"
  1$  e#   Copy from 1 back                    | ['L "LDLLDLDDL" 'L
  e=  e#   Count occurences                    | ['L 5
  *   e#   Repeat character                    | ["LLLLL"
}     e# End                                   | ["LLLLL" "DDDD"]
`     e# Stringify:                            | "[\"LLLLL\" \"DDDD\"]"
e# Implicit output: ["LLLLL" "DDDD"]
```
]