Print all strings from given array that can be typed using keys from a single row of a QWERTY keyboard | Function to print all strings that can be typed using keys of a single row in a QWERTY Keyboard ; Stores row number of all possible character of the strings ; Traverse the array ; If current string is not an empty string ; Sets true / false if a string can be typed using keys of a single row or not ; Stores row number of the first character of current string ; Stores length of word ; Traverse current string ; If current character can 't be  typed using keys of rowNum only ; Update flag ; If current string can be typed using keys from rowNum only ; Print the string ; Driver Code
def findWordsSameRow ( arr ) : NEW_LINE INDENT mp = { ' q ' : 1 , ' w ' : 1 , ' e ' : 1 , ' r ' : 1 , ' t ' : 1 , ' y ' : 1 , ' u ' : 1 , ' o ' : 1 , ' p ' : 1 , ' i ' : 1 , ' a ' : 2 , ' s ' : 2 , ' d ' : 2 , ' f ' : 2 , ' g ' : 2 , ' h ' : 2 , ' j ' : 2 , ' k ' : 2 , ' l ' : 2 , ' z ' : 3 , ' x ' : 3 , ' c ' : 3 , ' v ' : 3 , ' b ' : 3 , ' n ' : 3 , ' m ' : 3 } NEW_LINE for word in arr : NEW_LINE INDENT if ( len ( word ) != 0 ) : NEW_LINE INDENT flag = True NEW_LINE rowNum = mp [ word [ 0 ] . lower ( ) ] NEW_LINE M = len ( word ) NEW_LINE for i in range ( 1 , M ) : NEW_LINE INDENT if ( mp [ word [ i ] . lower ( ) ] != rowNum ) : NEW_LINE INDENT flag = False NEW_LINE break NEW_LINE DEDENT DEDENT if ( flag ) : NEW_LINE INDENT print ( word , end = ' ▁ ' ) NEW_LINE DEDENT DEDENT DEDENT DEDENT words = [ " Yeti " , " Had " , " GFG " , " comment " ] NEW_LINE findWordsSameRow ( words ) NEW_LINE