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'])
       3
       """
        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 2..how i can fix it?

Code: Select all
print(num_words_on_board([['A', 'N', 'T', 'T'], ['X', 'S', 'O', 'B']], ['ANT', 'BOX', 'SOB', 'TO']))
2
Last edited by Mekire on Thu Sep 26, 2013 12:24 pm, edited 1 time in total.
Reason: Lock
shahriyar.r
 
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
stranac
 
Posts: 1093
Joined: Thu Feb 07, 2013 3:42 pm


Return to General Coding Help

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 1 guest