联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp

您当前位置:首页 >> Python编程Python编程

日期:2018-08-09 01:50

"""Hashing it"""

from stats import StatCounter  # if you want to use it to check your answers

from classes_2 import CounterLinkNode, CounterLinkedList, nice_hash, hash_word



def print_hash_table(table_list):

   """Prints hash table --- used in testing so don't change this function"""

   for i in range(len(table_list)):

       print('{}: {}'.format(str(i), str(table_list[i])))



def hash_table_as_str(table_list):

   """Returns hash table as a string --- used in testing so don't change this function"""

   string = ''

   for i in range(len(table_list)):

       string += ('{}: {}\n'.format(str(i), str(table_list[i])))

   return string



# feel free to write helper functions to help :)




def word_counter_hash(words_list, slots):

   """This function takes a list of strings and

   returns a hash table (represented by a list,)

   were an empty slot contains None and a non

   empty slot contains a CounterLinkedList, and

   an integer for the number of string comparisons

   the function made.

   Each CounterLinkedList contains one or more

   CounterLinkNodes, which contain a string and the

   number of times that string occurred in the

   given list."""

   # ---start student section---

   comparison = 0

   table_size = slots

   my_list = CounterLinkedList()

   for word in words_list:

       print(word)

       if my_list.head == None:

           my_list.head = CounterLinkNode(word)

       else:

           index_number = hash_word(word, slots)

           current = my_list.head

           is_value = False

           while current is not None and not is_value:

               comparison += 1

               print(current)

               current_word = current.word

               if current_word == word:

                   res = count

                   is_value = True

                   count += 1

               else:

                   current = current.next_node

           if current_word != word:

               current.next_node = CounterLinkNode(word)

               

               


   return my_list, comparison          

   # ===end student section===


版权所有:编程辅导网 2021 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp