def test_read_file():
    word_list = read_file('oxford3000')
    for word_item in word_list:
        print(word_item)
    print('\n')

    new_item = get_word_item('dgrtyhaha,/hhh/')
    # word_list[1] = new_item
    add_word_item(word_list, new_item)
    for word_item in word_list:
        print(word_item)
    # list_not_exercised, list_all_correct, list_fault = divide_list(word_list)
    #
    # for word_item in list_not_exercised:
    #     print(word_item)
    # print('\n')
    #
    # for word_item in list_all_correct:
    #     print(word_item)
    # print('\n')
    #
    # for word_item in list_fault:
    #     print(word_item)
    # print('\n')

    write_file(word_list, 'oxford3000')
def read_file(file_name, what_to_get="sorted_list"):  # returns a list sorted by score
    with open('/home/junlingwang/Desktop/Vocabulary training/'+file_name+'.txt', 'r') as word_file:
        lines = word_file.readlines()  # lines is a list of strings
    word_list = []
    good_word_list = []
    for line in lines:  # line is a string in lines
        word_item_of_line = get_word_item(line.strip())
        if word_item_of_line.weight != 10000: # if weight is 10000, it means this item doesn't need to be practiced any more.
            word_list.append(word_item_of_line)  # strip(), delete blank characters including '\n'
        else:
            good_word_list.append(word_item_of_line)
    sorted_list = sorted(word_list, key=lambda item: item.score, reverse=True)  # word_list is not changed
    #  lambda function. Before the colon is parameter, after the colon is the result.
    # this lambda function is to sort the word list's item by their scores
    if what_to_get == "good_word_list":
        return good_word_list
    else:
        return sorted_list