Any idea whats a simple and fast way to get all words placed on a Scrabble board while the board is represented by 2D Array of chars?
Thanks in advance
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This is similar to Artsiom’s answer, but covers for the fact that a Scrabble board will have spaces in between words.
So assuming your “2D Array of chars” looks like this:
You can do the following:
Which gives:
What we’re doing is converting each row and column of characters in to strings like
'not mat'and then usingstr.split()to throw away the spaces to give us a list of words, throwing away anything that’s one letter long.Using
itertools.chain()just allows us to loop through the rows and columns in a single list comprehension.