[Question]
  [
The three rows of the qwerty keyboard are `qwertyuiop`, `asdfghjkl` and `zxcvbnm`. Your task is to find the longest word that can be typed using only one row of the keyboard, from a given list of words.
Sample input 1
```
artist
home
gas
writer
geology
marine
twerp
```
Output
```
writer
```
(Of the given words, only `gas`, `writer` and `twerp` can be written using a single row, and `writer` is the longest)
The words may not be actual words (so don't assume the third row to be invalid). However, you can assume that there will always be exactly one answer (no more, no less).
Sample input 2
```
wrhuji
bxnzmmx
gllwssjjd
vnccbb
lrkjhgfdsa
tttttt
```
Output
```
bxnzmmx
```
Additional punctuation and whitespaces can be provided in input (as per language requirements). However, no extra output should be given. Input and output are in lower case. **Shortest code wins.**
  
[Answer]
## Python 2, 84 bytes
```
lambda l:max(l,key=lambda w:(-len({"asdfghjklzxcvbnm".find(c)/9for c in w}),len(w)))
```
Finds the `max` of the input, comparing by fewer keyboard rows spanned, then in increasing length. The keyboard row value is extracted by `"asdfghjklzxcvbnm".find(c)/9`, which takes the middle row to `0`, the bottom row to `1`, and the top row, which is excluded, to `-1`, since `find` gives `-1` for missing values.
Other attempts:
```
lambda l:max((-len({"asdfghjklzxcvbnm".find(c)/9for c in w}),len(w),w)for w in l)[2]
lambda l:max(l,key=lambda w:len(w)-1./len({"asdfghjklzxcvbnm".find(c)/9for c in w}))
lambda l:max([w for w in l if len({"asdfghjklzxcvbnm".find(c)/9for c in w})<2],key=len)
```
[Answer]
# Japt, ~~32~~ 30 bytes
```
;Uf_¬£DbXu)f10Ãä¥ eÃn@Yl -XlÃg
```
[Test it online!](http://ethproductions.github.io/japt?v=master&code=O1VmX6yjRGJYdSlmMTDD5KUgZcNuQFlsIC1YbMNn&input=WwoiYXJ0aXN0IgoiaG9tZSIKImdhcyIKIndyaXRlciIKImdlb2xvZ3kiCiJtYXJpbmUiCiJ0d2VycCIKXQ==) Input is an array of strings.
### How it works
```
;Uf_  ¬ £  DbXu)f10Ã ä¥  eÃ n@  Yl -XlÃ g
;UfZ{Zq mX{DbXu)f10} ä== e} nXY{Yl -Xl} g
         // Implicit: U = input array of strings
;        // Reset variables A-L to various values.
         // D is set to the string "QWERTYUIOP\nASDFGHJKL\nZXCVBNM".
UfZ{   } // Take U and filter to only the items Z that return truthily to this function:
Zq       //  Split Z into chars, then
mX{    } //  map each char X by this function:
DbXu)    //   Return D.indexOf(X.toUpperCase()),
f10      //   floored to a multiple of 10.
         //  This maps each char to 0 for the top row, 10 for the middle, 20 for the bottom.
q ä==    //  Split the resulting string into chars and check each pair for equality.
e        //  Check that every item in the result is truthy. This returns true if all chars
         //  are on the same row; false otherwise.
         // Now we have only the words that are entirely on one row.
nXY{   } // Sort by passing each two args X and Y into this function:
Yl -Xl   //  Return Y.length - X.length. Sorts the longest to the front.
g        // Get the first item in the resulting array. Implicitly output.
```
[Answer]
# Python 2.5+ and 3, 93 bytes
Had to test how many strokes for this approach; this uses the fact that `a.strip(b)` results in empty string if `a` solely consists of characters that occur in b.
The function takes list of strings and returns a string.
```
lambda a:max(a,key=lambda x:(~all(map(x.strip,['qwertyuiop','asdfghjkl','zxcvbnm'])),len(x)))
```
[Answer]
## [Retina](https://github.com/mbuettner/retina/), 73 bytes
```
G`^([eio-rtuwy]+|[adfghjkls]+|[bcmnvxz]+)$
1!`(.)+(?!\D+(?<-1>.)+(?(1)!))
```
[Try it online!](http://retina.tryitonline.net/#code=R2BeKFtlaW8tcnR1d3ldK3xbYWRmZ2hqa2xzXSt8W2JjbW52eHpdKykkCjEhYCguKSsoPyFcRCsoPzwtMT4uKSsoPygxKSEpKQ&input=YXJ0aXN0CmhvbWUKZ2FzCndyaXRlcgpnZW9sb2d5Cm1hcmluZQp0d2VycAp3cmh1amkKYnhuem1teApnbGx3c3NqamQKdm5jY2JiCmxya2poZ2Zkc2EKdHR0dHR0)
Conclusion: Retina needs a sorting stage.
### Explanation
```
G`^([eio-rtuwy]+|[adfghjkls]+|[bcmnvxz]+)$
```
This is a grep stage: it only keeps lines which are matched by the regex. I.e. those which are formed exclusively from one of those character classes.
```
1!`(.)+(?!\D+(?<-1>.)+(?(1)!))
```
Now we just need to find the largest of the remaining strings. We do this by matching all words which are at least as long than all the words after them. The `1` is a new addition to Retina (released two days ago), which limits this match stage to considering only the first such match. And `!` instructs Retina to print the match (instead of counting it).
[Answer]
## Java, ~~154~~ 142 or ~~142~~ 130 bytes
[Because, ya know, Java.](http://meta.codegolf.stackexchange.com/a/5829)
[C#, for comparison](https://codegolf.stackexchange.com/a/75767/51825).
146 bytes if input has to be a single string with values separated by `\n`:
```
s->java.util.Arrays.stream(s.split("\n")).filter(g->g.matches("[wetyuio-r]*|[asdfghjkl]*|[zxcvbnm]*")).max((a,b)->a.length()-b.length()).get()
```
134 bytes if I can assume input as String[] instead:
```
s->java.util.Arrays.stream(s).filter(g->g.matches("[wetyuio-r]*|[asdfghjkl]*|[zxcvbnm]*")).max((a,b)->a.length()-b.length()).get()
```
Slightly ungolfed:
```
UnaryOperator<String> longestQwertyStr = s -> 
        java.util.Arrays.stream(s.split("\n")) // Split string input over `\n` and convert to Stream<String>
                .filter(g->g.matches("[wetyuio-r]*|[asdfghjkl]*|[zxcvbnm]*")) // Filter to Strings that only use characters from a single row
                .max((a,b)->a.length()-b.length()) // Find the max by comparing String length
                .get(); // Convert from Optional<String> to String and implicit return single statement lambda
```
Second lambda is a `Function<String[],String>`.
[Answer]
# Jelly, ~~40~~ 34 bytes
```
p“£vẈ¬ḣ“£AS°GƤg“£ḷḳƤ²ƤȤḤ»f/€fµL€Mị
```
[Try it online!](http://jelly.tryitonline.net/#code=cOKAnMOm4bmZxL9neuKAnMKi4buK4bmaLuG4hMOmK-KAnMKjMsmgyKXCouG5v8WSwqbCu2Yv4oKsZsK1TOKCrE3hu4s&input=&args=WyJhcnRpc3QiLCAiaG9tZSIsICJnYXMiLCAid3JpdGVyIiwgImdlb2xvZ3kiLCAibWFyaW5lIiwgInR3ZXJwIl0)
### How it works
```
p“£vẈ¬ḣ“£AS°GƤg“£ḷḳƤ²ƤȤḤ»f/€fµL€Mị
 “£vẈ¬ḣ“£AS°GƤg“£ḷḳƤ²ƤȤḤ»           Use dictionary compression to yield
                                    ['quipo twyer', 'adj flash jg', 'bcmnz xv'].
p                                   Cartesian product; for all pairs of an input
                                    string and one of the rows.
                         f/€        Reduce each pair by filter, keeping only the
                                    letters in the input string that are on that
                                    particular keyboard row.
                            f       Filter the results, keeping only filtered words
                                    that occur in the input.
                             µ      Begin a new chain.
                              L€    Get the length of each kept word.
                                M   Get the index corr. to the greatest length.
                                 ị  Retrieve the word at that index.
```
[Answer]
# Python 3, 98
Saved 5 bytes thanks to Kevin.  
Saved 3 bytes thanks to PM 2Ring.  
Saved 3 bytes thanks to Antti Haapala.
Brute forcing it at the moment. I filter the words down to only those contained by a single row, and then sort for max string length.
```
lambda a:max(a,key=lambda x:(any(map(set(x).__le__,['qwertyuiop','asdfghjkl','zxcvbnm'])),len(x)))
```
Test cases:
```
assert f(['asdf', 'qwe', 'qaz']) == 'asdf'
assert f('''artist
home
gas
writer
geology
marine
twerp'''.splitlines()) == 'writer'
assert f('''wrhuji
bxnzmmx
gllwssjjd
vnccbb
lrkjhgfdsa
tttttt'''.splitlines()) == 'bxnzmmx'
```
[Answer]
## PowerShell v2+, 72 bytes
```
($args-match"^([qwertyuiop]+|[asdfghjkl]+|[zxcvbnm]+)$"|sort Length)[-1]
```
Takes input via command-line arguments as `$args`, then uses the [`-match` operator](https://technet.microsoft.com/en-us/library/hh847759(v=wps.620).aspx) with a regex to select only the words that are exclusively made up of one keyboard row. We pipe those results into [`Sort-Object`](https://technet.microsoft.com/en-us/library/hh849912(v=wps.620).aspx) that sorts by the property `Length`. We can do this since strings in PowerShell are all of the `System.String` type, which includes `.Length` as a sortable property. This sorts the strings into ascending order by length, so we take the last one with `[-1]`, leave it on the pipeline, and output is implicit.
**Example**
```
PS C:\Tools\Scripts\golfing> .\longest-word-qwerty-keyboard.ps1 asdf qwe zxc typewriter halls establishment
typewriter
```
[Answer]
# Pyth, ~~45~~ 35 bytes
Thanks to @FryAmThe Eggman for saving me some bytes!
```
elDf}k-LTc."`z:I¿Ç  Ì(T4²ª$8·"\`Q
```
[Try it here!](http://pyth.herokuapp.com/?code=elDf%7Dk-LTc.%22%60z%02%3AI%C2%84%C2%BF%C3%87%09%C3%8C%28T4%C2%B2%C2%AA%24%148%C2%B7%22%5C%60Q&input=[%27wrhuji%27%2C+%27bxnzmmx%27%2C+%27gllwssjjd%27%2C+%27vnccbb%27%2C+%27lrkjhgfdsa%27%2C+%27tttttt%27]&test_suite_input=artist%0Ahome%0Agas%0Awriter%0Ageology%0Amarine%0Atwerp%0A&debug=0&input_size=7)
Takes input as a list of words.
## Explanation
```
elDf}k-LTc."..."\`Q   # Q = list of all input words
   f              Q   # Filter input with T as lambda variable
         c."..."\`    # List of all keyboard rows
      -LT             # Remove all letters of the current input row from the current input
                      # word. Results in a list of 3 string with one being empty if
                      # the word can be typed with one row
    }k                # Check if the list contains an emtpy string
elD                   # order result list by length and take the last
```
[Answer]
# Ruby, 88 82 69
If I'm not allowed to take a list of strings and must take a multiline string, add +12 to the score and add `.split('\n')` right before the `.grep` call.
Thanks CatsAreFluffy for teaching me about stabby lambdas in Ruby, and further optimizations from manatwork
```
->x{x.grep(/^([o-rwetyui]+|[asdfghjkl]+|[zxcvbnm]+)$/).max_by &:size}
```
[Answer]
## awk , ~~92~~ ~~84~~ 81 bytes
```
(/^([wetyuio-r]+|[asdfghjkl]+|[zxcvbnm]+)$/)&&length>length(a){a=$0}END{print a}  
```
saved 3 bytes thanks to @Wolfgang suggestion
[Answer]
# C#, 141 / 112 / (120 bytes)
Contender for worst golfing language, for obvious reasons. Uses "my" locale with qwertz instead of qwerty but works fine otherwise.
Full program without where:
```
static void Main(string[]a){Console.WriteLine(a.OrderBy(x=>x.Length).Last(x=>Regex.IsMatch(x,"^([qwertzuiop]+|[asdfghjkl]+|[yxcvbnm]+)$")));}
```
Only output without Where:
```
Console.WriteLine(a.OrderBy(x=>x.Length).Last(x=>Regex.IsMatch(x,"^([qwertzuiop]+|[asdfghjkl]+|[yxcvbnm]+)$")));
```
Only output (original):
```
Console.WriteLine(a.Where(x=>Regex.IsMatch(x,"^([qwertzuiop]+|[asdfghjkl]+|[yxcvbnm]+)$")).OrderBy(x=>x.Length).Last());
```
[Answer]
# `bash`, 105 bytes
And various other utilities, of course.
```
egrep -x '[wetyuio-r]+|[asdfghjkl]+|[zxcvbnm]+'|awk '{print length($0)"\t"$0;}'|sort -n|cut -f2|tail -n1
```
[Answer]
# [MATL](https://esolangs.org/wiki/MATL), 54 bytes
```
[]y"@Y:nh]2$SP"@Y:!t'asdfghjkl'mw'zxcvbnm'myy+~hhAa?@.
```
This works with [current version (14.0.0)](https://github.com/lmendo/MATL/releases/tag/14.0.0) of the language/compiler.
Input format is (first example)
```
{'artist' 'home' 'gas' 'writer' 'geology' 'marine' 'twerp'}
```
or (second example)
```
{'wrhuji' 'bxnzmmx' 'gllwssjjd' 'vnccbb' 'lrkjhgfdsa' 'tttttt'}
```
[**Try it online!**](http://matl.tryitonline.net/#code=W115IkBZOm5oXTIkU1AiQFk6IXQnYXNkZmdoamtsJ213J3p4Y3Zibm0nbXl5K35oaEFhP0Au&input=eydhcnRpc3QnICdob21lJyAnZ2FzJyAnd3JpdGVyJyAnZ2VvbG9neScgJ21hcmluZScgJ3R3ZXJwJ30)
### Explanation
```
[]               % push empty array. Will be used for concatenation
y                % take input array implicitly at bottom of stack, and copy onto top
"                % for each string
  @Y:            %   push current string
  nh             %   get its length. Concatenate with array of previous lengths
]                % end for each
2$S              % sort the original copy of input array by increasing string length
P                % flip: sort by decreasing length
"                % for each string in decreasing order of length
  @Y:!           %   push that string as a column char vector
  t'asdfghjkl'm  %   duplicate. Tru for chars in 2nd row of keyboard
  w'zxcvbnm'm    %   swap. True for chars in 3rd row of keyboard
  yy+~           %   duplicate top two arrays, sum, negate: true for chars in 1st row
  hh             %   concatenate horizontally twice
  Aa             %   true if any column has all true values
  ?              %   if that's the case
    @            %     push string  
    .            %     break for each loop
                 %   end if implicitly
                 % end for each
                 % display implicitly
```
[Answer]
# Perl, 81 bytes
`$a=$1 if/^([wetyuio-r]+|[asdfghjkl]+|[zxcvbnm]+)$/&&1<<y///c>$a=~y///c;END{say$a}`
Symbol to letter count pretty high.
[Answer]
# Groovy, 65 characters
```
{it.grep(~/[o-rwetyui]+|[asdfghjkl]+|[zxcvbnm]+/).max{it.size()}}
```
Sample run:
```
groovy:000> ({it.grep(~/[o-rwetyui]+|[asdfghjkl]+|[zxcvbnm]+/).max{it.size()}})(['wrhuji', 'bxnzmmx', 'gllwssjjd', 'vnccbb', 'lrkjhgfdsa', 'tttttt'])
===> bxnzmmx
```
Note that the regular expression used by `.grep()` not requires anchoring, allowing to spare the grouping too:
```
groovy:000> ['ab', 'ac', 'bc', 'abc', 'aca', 'bbc'].grep ~/[ac]+|b+/
===> [ac, aca]
```
[Answer]
# [Japt](https://github.com/ETHproductions/japt) [`-h`](https://codegolf.meta.stackexchange.com/a/14339/), 18 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
```
;k_£D·bøXuÃä¦ dÃñÊ
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&flags=LWg&code=O2tfo0S3YvhYdcPkpiBkw/HK&input=WwoiYXJ0aXN0IgoiaG9tZSIKImdhcyIKIndyaXRlciIKImdlb2xvZ3kiCiJtYXJpbmUiCiJ0d2VycCIKXQ)
```
;k_£D·bøXuÃä¦ dÃñÊ     :Implicit input of array
 k                     :Remove elements that return true
  _                    :When passed through the following function
   £                   :  Map each character X
;   D                  :    "QWERTYUIOP\nASDFGHJKL\nZXCVBNM"
     ·                 :    Split on newlines
      b                :    Index of first element that
       ø               :      Contains
        Xu             :      Uppercase X
          Ã            :  End map
           ä           :  Consecutive pairs of characters
            ¦          :  Reduced by checking for inequality
              e        :  Any true?
               Ã       :End filter
                ñ      :Sort by
                 Ê     :  Length
                       :Implicit output of last element
```
[Answer]
# [Perl 5](https://www.perl.org/) `-l`, 75 bytes
```
map$a[y///c]=$_,grep/^([weo-rtyui]+|[asdfghjkl]+|[zxcvbnm]+)$/,<>;say pop@a
```
[Try it online!](https://tio.run/##FcdLDsIgEADQPadw0YWmReqiKz/xAp6gqWasI0WhTAa0Yjy7GN/uEbJtcnZABbRJKdV32@JUaUZSx3k7oZcc08N05aeFcLnq4Xa3/7xf/fM8uq5cFKra7NYB0ow87SFn4GhCFIN3KDQEMbGJyEKjt14n4YDNiCJOyPT1FI0fQ5aHZlmv6iztDw "Perl 5 – Try It Online")
[Answer]
# [K (ngn/k)](https://codeberg.org/ngn/k), 56 bytes
```
{x@*&|/&/''~^($`qwertyuiop`asdfghjkl`zxcvbnm)?\:x@:>#'x}
```
[Try it online!](https://ngn.bitbucket.io/k#eJwdjMkSgyAQRO/5ihRJueTi3VQlfkgqJSirIAZQ0CzfHrAP02+mppvU79Bcsk+VVXn+exbn9uWxcevM9dRC2xPKxCDbLXQLGlV5f9ShqW+nPHwPB3IsADSOWweugGmFo1Fo4/SGO2zSirXUdI2koOFj+nCxfwLlnvaGzYLHIwrjplRICSm9tUL0kZex6xCKIM0gGCW9halgFyj/5N0+kg==)
* `x@:>#'x` sort the input (a list of strings) by their lengths, descending, updating `x` with the result
* `($`qwertyuiop`asdfghjkl`zxcvbnm)` generate a list of strings representing which letters are present on each row of a qwerty keyboard
* `~^(...)?\:x` check whether or not each letter of each input word is present or not in each keyboard line
* `&/''` determine if all letters of each input word are present in the same keyboard line or not
* `|/` check that there is at least one keyboard line containing all the letters of each input word
* `x@*&` return the longest word in the input where the above criteria are met
]