how many words appear on board

This is the place for queries that don't fit in any of the other categories.

how many words appear on board

Postby shahriyar.r » Thu Sep 26, 2013 12:07 pm

Code: Select all
  def num_words_on_board(board, words):
        """ (list of list of str, list of str) -> int
       Return how many words appear on board.
       >>> num_words_on_board([['A', 'N', 'T', 'T'], ['X', 'S', 'O', 'B']], ['ANT', 'BOX', 'SOB', 'TO'])
        return_str = ''
        for i in board:
            for a in i:
                return_str = return_str + a
        count = 0
        for b in words:
            if b in return_str:
                count = count + 1
        return count

It must returns 3 as sample example shows. but in my code it return i can fix it?

Code: Select all
print(num_words_on_board([['A', 'N', 'T', 'T'], ['X', 'S', 'O', 'B']], ['ANT', 'BOX', 'SOB', 'TO']))
Last edited by Mekire on Thu Sep 26, 2013 12:24 pm, edited 1 time in total.
Reason: Lock
Posts: 7
Joined: Thu Aug 29, 2013 9:50 am

Re: how many words appear on board

Postby stranac » Thu Sep 26, 2013 1:12 pm

My guess would be that you need to check for words both vertically and horizontally.
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
Posts: 1790
Joined: Thu Feb 07, 2013 3:42 pm

Return to General Coding Help

Who is online

Users browsing this forum: Bing [Bot], Yahoo [Bot] and 8 guests