[Question]
  [
Given a nonempty finite list of integers, output a *truthy* value if there are exactly two equal entries and all other entries are distinct, and a *falsey* value otherwise.
### Examples
```
truthy:
[1,1]
[1,2,1]
[1,6,3,4,4,7,9]
 
falsey:
[0]
[1,1,1]
[1,1,1,2]
[1,1,2,2]
[2,1,2,1,2]
[1,2,3,4,5]
```
  
[Answer]
# Python 3, ~~30~~ 28 bytes
```
lambda m:len({*m})+1==len(m)
```
[Try it online!](https://tio.run/##NYvNCsMgEITveYo9uq2ExvSHBvIkbQ4WDRXUiEohlD67VUkY2P1mZtet8b3YPs0wwjNpbl6Cgxm0tOR7MD88duNYjMGkjFt8hLCGZl48aGUlKFt8G6JQtvWSC4JtcFrF0gaCQwMAzisbyUzkh2tSCkRMj452U5Mn2/aV9vScdaP37E8122@K2EasEqu0p6z@XqY/ "Python 3 – Try It Online")
`{*m}` casts the list to a `set` object, an unordered list of items without duplicates. Doing this will always decrease the length of the list by the number of duplicates in it. By computing how much the length has changed, we can easily tell if the list had a single duplicate and return the result of the test.
-2 bytes thanks to ovs.
[Answer]
# [Husk](https://github.com/barbuz/Husk), 4 bytes
```
εṠ-u
```
[Try it online!](https://tio.run/##yygtzv6vkKtR/KipsUjz0Lb/57Y@3LlAt/T////RhjqGsVxA0ghKm@kY65gAobmOJZBvABaDqQFBIyjLCMwyArNgokZgvaaxAA "Husk – Try It Online")
## Explanation
```
εṠ-u  Implicit input.
   u  Unique elements.
 Ṡ-   Delete them from input, counting multiplicities.
ε     Is the result a singleton list?
```
[Answer]
# [Haskell](https://www.haskell.org/), 34 bytes
```
f x=[1|a<-x,b<-x,a==b]==1:1:(1<$x)
```
[Try it online!](https://tio.run/##y0gszk7Nyfn/P02hwjbasCbRRrdCJwlEJNraJsXa2hpaGVppGNqoVGj@z03MzFOwVUjJ51IAgoKizLwSBRWFNIVoQx3DWEwxI6yiZjrGOiZAaK5jiSFrgEU9drNB0AiruBEWcSOwOHYdRmD3mMZy/QcA "Haskell – Try It Online") Based on [H.PWiz' answer](https://codegolf.stackexchange.com/a/145064/56433).
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~8~~ 5 bytes
```
QL‘=L
```
[Try it online!](https://tio.run/##y0rNyan8/z/Q51HDDFuf/4fbHzWt@f8/2lDHTMdYxwQIzXUsY3UUgAJAGAsA "Jelly – Try It Online")
# Explanation
```
QL‘=L  - Main link, argument L (a list)   e.g [1,6,3,4,4,7,9]
Q      - Deduplicated elements                [1,6,3,4,7,9]
 L     - Length                               6
  ‘    - Increment                            7
    L  - Length of the input                  7 ([1,6,3,4,4,7,9])
   =   - Are they equal?                      1
```
If the output values can be any consistent values, then `QL_L` works, which outputs `-1` for truthy and any other non-positive number for falsey (thanks @JonathanAllan)
[Answer]
# [MATL](https://github.com/lmendo/MATL), ~~7~~, 6 bytes
```
&=sp4=
```
[Try it online!](https://tio.run/##y00syfn/X822uMDE9v//aEMdMx1jHRMgNNexjAUA "MATL – Try It Online")
One byte saved thanks to @Guiseppe!
Explanation:
```
&=  % Table of pair-wise equality comparisons
    %
    % [1 0 0 0 0 0 0
    %  0 1 0 0 0 0 0
    %  0 0 1 0 0 0 0
    %  0 0 0 1 1 0 0
    %  0 0 0 1 1 0 0
    %  0 0 0 0 0 1 0
    %  0 0 0 0 0 0 1]
    %
s   % Sum each Column. Stack:
    %
    % [1 1 1 2 2 1 1]
    %
p   % Product of the array. Stack:
    %
    % [4]
    %
4=  % Compare the stack to '4'
```
[Answer]
# JavaScript (ES6), 30 bytes
```
a=>new Set(a).size==a.length-1
```
[Try it online](https://tio.run/##y0osSyxOLsosKNHNy09J/Z@cn1ecn5Oql5OfrqHxP9HWLi@1XCE4tUQjUVOvOLMq1dY2US8nNS@9JEPX8L@mRrShjpmOsY4JEJrrWMZqav4HAA)
[Answer]
# [Pushy](https://github.com/FTcode/Pushy), 8 bytes
Simple implementation of checking whether `len(set(list)) == len(list)-1`:
```
LtvuL^=#
```
Explanation:
```
       \ Implicit: Put all input on stack
Ltv    \ Get the stack length - 1, save in auxiliary stack
u      \ Remove non-unique elements
L      \ Get the new length
^=     \ Compare with the previously saved length
#      \ Print result
```
This works as the length will only decrease by 1 if there was only exactly 1 non-distinct integer in the initial list.
[Try it online!](https://tio.run/##Kygtzqj8/9@npKzUJ85W@f///9GGOmY6xjomQGiuYxkLAA "Pushy – Try It Online")
[Answer]
# [Octave](https://www.gnu.org/software/octave/), 25 bytes
This is not using a `group` or `unique` approach as many of the other answers, but rather the "cartesian product" of all possible comparisions.
```
@(x)nnz(triu(x==x',1))==1
```
### Explanation
```
             x==x'        %create a matrix where the entry at (i,j) compares whether x(i) == x(ju)
        triu(x==x',1)     %only consider the strict upper triangular matrix
    nnz(triu(x==x',1))    %count the number of nonzero entries
@(x)nnz(triu(x==x',1))==1 %check whether this number is actually 1
```
[Try it online!](https://tio.run/##y08uSSxL/f/fQaNCMy@vSqOkKLNUo8LWtkJdx1BT09bW8H9iXrFGtKGOoY6xjomOaazmfwA "Octave – Try It Online")
And because no program would be complete without a convolution (thanks @LuisMendo for fixing a mistake):
# [Octave](https://www.gnu.org/software/octave/), 40 bytes
```
@(x)nnz(~conv(sort(x),-1:2:1,'same'))==1
```
[Try it online!](https://tio.run/##y08uSSxL/f/fQaNCMy@vSqMuOT@vTKM4v6gEKKCja2hlZGWoo16cmJuqrqlpa2v4PzGvWCPaUMdQx1jHRMc0VvM/AA "Octave – Try It Online")
[Answer]
# [J](http://jsoftware.com/), ~~7~~ 6 bytes
```
=&#0,=
```
`=` check every element for equality with every unique element, creates a matrix with **m** rows for **m** unique elements.  
`0,` add an empty row on top.  
`=&#` does the number of rows equal the length of input?
[Try it online!](https://tio.run/##y/r/P81WT8FWTdlAx/Z/anJGvkOag52CoYKhtaGCEZg0UzBWMAFCcwVLawMgHyIHgkZg2ghIG4FpiIgRWL3pfwA)
[Answer]
## [Retina](https://github.com/m-ender/retina), ~~15~~ ~~12~~ 11 bytes
*Thanks to Neil for saving 1 byte.*
```
D`
Mm2`^$
1
```
[Try it online!](https://tio.run/##K0otycxL/K@qEZyg898lgcs31yghToXL8P9/Qx1DLkMdIzBppmOsYwKE5jqWXAZAPkQOBI3AtBGQNgLTEBEjsHpTAA "Retina – Try It Online")
Input is linefeed-separated. (The test suite uses comma-separation for convenience.)
### Explanation
```
D`
```
Deduplicate the lines in the input, which removes any integer that has appeared before (but leaves the surrounding linefeed(s)).
```
Mm2`^$
```
Count the number of empty lines, which is equal to the number of duplicates we removed, but only consider the first two matches. So the output will only be `0` (no duplicates), `1` (one duplicate), `2` (two or more duplicates).
```
1
```
Make sure that exactly one duplicate was removed.
[Answer]
# [R](https://www.r-project.org/), ~~32~~ 31 bytes
*-1 byte thanks to @JarkoDubbeldam*
```
cat(sum(duplicated(scan()))==1)
```
[Try it online!](https://tio.run/##K/r/PzmxRKO4NFcjpbQgJxPISU3RKE5OzNPQ1NS0tTXU/G@oYPgfAA)
Reads from stdin, writes to stdout.
`duplicated` iterates through the list, replacing the values of `l` with `TRUE` if that value occurs earlier in the list, and `FALSE` otherwise. If there's a unique pair of soulmates, there should be exactly one `TRUE` value, so the sum should be `1`.
[Answer]
# [K (ngn/k)](https://codeberg.org/ngn/k), 10 bytes
```
1=-/#'1?:\
```
[Try it online!](https://ngn.codeberg.page/k#eJxNj+FqwyAUhf/7FMIG20Cr3iQtVcYeJAtUMm1C07hFAwlje/YZ25BxQL9z77kXtVK8UvbwJN7kO0JBfj+W8+8gLcZ4Uid3Uc8nq9tOTWpWw0v1EzOlwEKJKgFsuMcZzqMO+HgrEa74rbUMbIhhM7AaSOZfD9K6YrGIoSaETy8Zq92HObvO7nzQ9cVMdaP7s9nV7sq+RuND63rPRF7wjLO2p97ooW6os1RT78buqoOJPxjG0MwSlYLEh8YT7veeZCSPOpBjhTCyuvNmyfHUXdOL4E6QCBKtVUhbigr9AUhbWkw=)
A tacit version of `{1=(#x)-#?x}`.
* `1?:\` run a distinct-do-scan for one iteration, returning a two-item list containing the original input and the distinct items of the input
* `#'` take the count/length of each item in that list
* `1=-/` is the difference between the counts one?
[Answer]
# [K (ngn/k)](https://codeberg.org/ngn/k), 8 bytes
```
2=*/#'=:
```
[Try it online!](https://ngn.codeberg.page/k#eJxNj/1qwyAUxf/3KYQN9oGpepO0VOmThEDFaROaxi0aSBjbs8/YhowD+jv3nntRK+D0Tp9eTgKhIL6fq/l3EBZjPMmzu8rXs1VtJyc5y+Gt/omZimMueZ0ANtzjHBdRB3y8lwiT7N5aBjbEsBlYDSTzrwdpXblYRFETwqcXlGr3YS6uszsflL6aSTeqv5iddjf6NRofWtd7youS5Yy2feaNGnSTOZupzLuxu6lg4g+GMTSzQBUn8aHxhMe9Jzkpog7kWCOMrOq8WXIsddf0IngQJIJEaxXSlrJGf4TrWbs=)
Checks if the product of the counts of unique elements is 2. This works because the only way to get the product of 2 is (1, 1, 1, ..., 1, 2) in some order.
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 4 bytes
```
{¥_O
```
[Try it online!](https://tio.run/##MzBNTDJM/f@/@tDSeP///6MNdcx0jHVMgNBcxzIWAA "05AB1E – Try It Online")
Outputs `1` as truthy, any other non-negative integer as falsy. In 05AB1E, `1` is the only truthy number (thanks @Emigna for the insight!).
### Explanation
```
{       Implicit input. Sort
 ¥      Consecutive differences
  _     Boolean negate
   O    Sum. Implicit display
```
[Answer]
# Ruby, 32 bytes
```
->(s){s.uniq.length==s.length-1}
```
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), 6 bytes
```
qtlQl{
```
**[Verify all the test cases.](https://pyth.herokuapp.com/?code=qtlQl%7B&test_suite=1&test_suite_input=%5B1%2C1%5D%0A%5B1%2C2%2C1%5D%0A%5B1%2C6%2C3%2C4%2C4%2C7%2C9%5D%0A%5B0%5D%0A%5B1%2C1%2C1%5D%0A%5B1%2C1%2C1%2C2%5D%0A%5B1%2C1%2C2%2C2%5D%0A%5B2%2C1%2C2%2C1%2C2%5D%0A%5B1%2C2%2C3%2C4%2C5%5D&debug=0)**
* `l{` - Gets the number of unique elements.
* `tlQ` - Gets the length of the input list, decremented.
* `q` - Checks equality.
# 7 bytes
```
q1l.-Q{
```
**[Verify all the test cases](https://pyth.herokuapp.com/?code=O&test_suite=1&test_suite_input=%5B1%2C1%5D%0A%5B1%2C2%2C1%5D%0A%5B1%2C6%2C3%2C4%2C4%2C7%2C9%5D%0A%5B0%5D%0A%5B1%2C1%2C1%5D%0A%5B1%2C1%2C1%2C2%5D%0A%5B1%2C1%2C2%2C2%5D%0A%5B2%2C1%2C2%2C1%2C2%5D%0A%5B1%2C2%2C3%2C4%2C5%5D&debug=0)**
[Answer]
# [C# (.NET Core)](https://www.microsoft.com/net/core/platform), 35 + 18 bytes
+18 for using `System.Linq`.
```
n=>n.Distinct().Count()==n.Length-1
```
[Try it online!](https://tio.run/##LY6xDoJAEERr@IotIYFLsEVoNFaamFhYEIrzPHET3Iu3i8YQvv2EhGammXkzhnPjvA0DI3Vw@bHYlzoivcvY9JoZzt51Xr9gjCMWLWjg4/AOJ42UsPi51bSgfcfpEolWwmEgs0WSps3g5lxfwwOqQFVNao8sSEaSVO3cQLNXFamjpU6eeRHKeEXsHLHrrbp6FDs/sskjIfud10YoMthkixZTmpbxNIU/ "C# (.NET Core) – Try It Online")
**67 byte alternative without Linq:**
```
n=>new System.Collections.Generic.HashSet<int>(n).Count==n.Length-1
```
[Try it online!](https://tio.run/##Pc6xCsJAEEXR2nzFlAnEhdhq0ghqoSCksBCLdR2Tgc0s7IyKhHx7jCD25z6ek7kLEUfnrQgcY2ii7aBPZqJWycEz0A0OljgVjcTN@QI2NpJ9yax@i2JnNg92K2I9X3K4huAruEM5clkxvuBn1sF7dEqBxWyRMZIzOyttjQrftko5m9CDtSzZ7JEbbefFuEz@PUvwaE6RFPfEmN7TaX6600ORwyKHYsiyZTIM4wc "C# (.NET Core) – Try It Online")
[Answer]
## Excel, 42 bytes
**Danish language version**
```
=TÆLV(A:A)=SUM(--(FREKVENS(A:A,A:A)>0))+1
```
Assumes each integer from the list in separate cell in column `A`.  
If we were allowed for inconsistent *falsey* values, we could save 3 bytes:
```
=TÆLV(A:A)+SUM(-(FREKVENS(A:A,A:A)>0))
```
**English language version (44 bytes)**
```
=COUNTA(A:A)=SUM(--(FREQUENCY(A:A,A:A)>0))+1
```
[Answer]
# [PowerShell](https://github.com/TryItOnline/TioSetup/wiki/Powershell), ~~40~~ 37 bytes
```
($args|sort -u).count-eq$args.count-1
```
[Try it online!](https://tio.run/##K8gvTy0qzkjNyfn/X0MlsSi9uKY4v6hEQbdUUy85vzSvRDe1ECwM5Rn@///f8L/Rf0MA "PowerShell – Try It Online")
The `Sort-Object` command (alias `sort`) with the `-u`nique flag pulls out only the unique components of the input. For example, for input `@(1,3,3,2)`, this will result in `@(1,2,3)`.
Thus, we just need to make sure that the `.count` of this object (i.e., how many elements it has) is `-eq`ual to the `.count` of our input array `-1` (i.e., we have exactly one duplicate entry).
*Saved 3 bytes thanks to Sinusoid.*  
*Fixed bug thanks to TessellatingHeckler.*
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 10 bytes
```
ċ@€`QṢ⁼1,2
```
[Try it online!](https://tio.run/##y0rNyan8//9It8OjpjUJgQ93LnrUuMdQx@j///@GOmY6xjomQGipYw4A "Jelly – Try It Online")
a longer but different approach
[Answer]
# [Haskell](https://www.haskell.org/), 37 bytes
```
f x=sum[1|0<-(-)<$>x<*>x]==2+length x
```
[Try it online!](https://tio.run/##y0gszk7Nyfn/P02hwra4NDfasMbARldDV9NGxa7CRsuuItbW1kg7JzUvvSRDoeJ/bmJmnoKtQkFRZl6JgopCmkK0oY6hjrGOSex/AA "Haskell – Try It Online")
[Answer]
# [Perl 5](https://www.perl.org/), 36 + 1 (`-a`) = 37 bytes
```
map$k{$_}++,@F;@a=keys%k;say@a+1==@F
```
[Try it online!](https://tio.run/##K0gtyjH9/z83sUAlu1olvlZbW8fBzdoh0TY7tbJYNdu6OLHSIVHb0NbWwe3/f0MFQwVjBRMF03/5BSWZ@XnF/3V9TfUMDA3@6yYCAA "Perl 5 – Try It Online")
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 5 bytes
```
gIÙg-
```
[Try it online!](https://tio.run/##MzBNTDJM/f8/3fPwzHTd//@jDXWMdIx1THRMYgE "05AB1E – Try It Online")
```
g     # Get number of elements in input
 IÙg  # Get number of unique elements in input
    - # Subtract
```
In 05AB1E 1 is the only truthy value, so for a truthy result there must be exactly 1 duplicate element removed by the uniquify.
[Answer]
# [Haskell](https://www.haskell.org/), 37 bytes
```
f x=sum[1|a<-x,b<-x,a==b]==2+length x
```
[Try it online!](https://tio.run/##y0gszk7Nyfn/P02hwra4NDfasCbRRrdCJwlEJNraJsXa2hpp56TmpZdkKFT8z03MzFOwVUjJ51IAgoKizLwSBRWFNIVoQx3DWEwxI6yiZjrGOiZAaK5jiSFrgEU9drNB0AiruBEWcSOwOHYdRmD3mMZy/QcA "Haskell – Try It Online")
[Answer]
# [Octave](https://www.gnu.org/software/octave/) / MATLAB (with Statistics package / toolbox), 21 bytes
```
@(x)nnz(~pdist(x))==1
```
Anonymous function. Input is a column vector. Output is `true` (displayed as `1`) or `false` (displayed as`0`).
[**Try it online!**](https://tio.run/##y08uSSxL/Z9mq6en999Bo0IzL69Ko64gJbO4BMjRtLU1/J@mEW1orWAYq8kFYRkhc8ysFYytFUzAyNxawRIiYQCXR9EJQUbIfCM43wjGR1FiBDPfNFbzPwA "Octave – Try It Online")
### Explanation
`pdist(x)` computes a vector of Euclidean distances between all pairs of rows from `x`. It considers each pair only once (order of the two rows doesn't matter), and doesn't consider pairs formed by the same row twice.
In our case `x` is a column vector, so Euclidean distance between two rows is just absolute difference between the two numbers.
`~` is logical (Boolean) negation, `nnz` is number of nonzeros, and `==1` compares to `1`. So the result is `true` if and only if there is only one pair that gives zero distance.
[Answer]
# [Jq 1.5](https://stedolan.github.io/jq/), ~~53~~ 25 bytes
```
length-(unique|length)==1
```
Inspired by [Riley's answer](https://codegolf.stackexchange.com/questions/145030/in-search-of-a-soulmate/145061#145061) and much shorter then my original solution.
[Try it online!](https://tio.run/##yyr8Hx1tqGMYqwMkjaC0mY6xjgkQmutYAvkGYDGYGhA0grKMwCwjMAsmagTWaxobGx1b8z8nNS@9JENXozQvs7A0tQbC1bS1Nfz//19@QUlmfl7xf13dvNKcHN3MvILSEiCnKLFcN7@0BMgBAA "jq – Try It Online")
[Answer]
# Julia, ~~39~~ 26 bytes
```
!a=sum(a.==a')==endof(a)+2
```
## Explanation
The code generates a 2-dimensional table of booleans, which is then collected using the sum function, counting the number of same-element pairs in the cartesian square of A. Then this is compared to the length of the string plus two, and the quantities are equal only when there is exactly one repeat character. 
This code redefines the NOT operator. 
[Answer]
# [Octave](https://www.gnu.org/software/octave/), ~~23~~ 26 bytes
```
@(x)prod(sum(x==x'))==4
```
[Try it online!](https://tio.run/##y08uSSxL/Z9mq6en999Bo0KzoCg/RaO4NFejwta2Ql1T09bW5H9aflFuYolCcn5uQWJyCZdqSVFpSUalFVeaRrShjmGsJoRhhGCa6RjrmAChuY4lUIhLNS0xpzgVosEApgZJJwgaIXOQZIxgMkZgDpJCI7AlprGa/wE "Octave – Try It Online")
The `x==x'` part was inspired by [flawr's answer](https://codegolf.stackexchange.com/a/145046/31516). This is longer than Luis' answer, but it doesn't use any toolboxes.
### Explanation:
This is an anonymous function that takes a vector `x` as input, and compares it to itself transposed. This will give a matrix where all diagonal elements are `1`, and any off diagonal elements signals that there are duplicates elements.
The sum along any given column shows how many duplicates there are of that number. We want two of the numbers to have a duplicate, so we two values equal to two, and the rest unequal to two.
If we take the product of this matrix, we'll get `4` if there are only two equal elements (`2*2*1*1*1*1*...`), and something other than `4` if there are no duplicates, or more than two.
[Answer]
# PHP, 46 bytes
```
<?=count(array_unique($argv))==count($argv)-1;
```
Counts the number of entries in [`$argv`](http://php.net/manual/en/reserved.variables.argv.php) and compares it to the number of unique entries. If the former is higher than the latter by 1 then truthy, else falsey.
[Try it on eval.in!](https://eval.in/878751)
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), ~~6~~ 5 bytes
```
{¥>ΘO
```
[Try it online!](https://tio.run/##MzBNTDJM/f@/@tBSu3Mz/P//jzbUUTDTUTDWUTABI3MdBctYAA "05AB1E – Try It Online")
```
{¥>ΘO   # example input:               [1, 6, 3, 4, 4, 7, 9]
{       # sort                      -> [1, 3, 4, 4, 6, 7, 9]
 ¥      # get deltas                -> [  2, 1, 0, 2, 1, 2 ]
  >     # increment                 -> [  3, 2, 1, 3, 2, 3 ]
   Θ    # truthify (only 1 gives 1) -> [  0, 0, 1, 0, 0, 0 ]
    O   # sum                       -> 1
```
`1` being the only truthy value in 05AB1E, we can stop here. (Thanks @Emigna for pointing that out.)
To get only two distinct values, we can optionally add:
```
     Θ  # equals 1?                 -> 1
```
]