def test_sort_words():
    source = unit6utils.get_input_file("unit6_testinput_02.txt")
    expected = unit6utils.get_input_file("unit6_expectedoutput_02.txt")
    destination = unit6utils.get_temp_file("unit6_output_02.txt")
    sort_words(source, destination)
    result = [word.strip() for word in open(destination)]
    expected = [word.strip() for word in open(expected)]
    assert expected == result
Пример #2
0
def test_anagram_sort():
    source = unit6utils.get_input_file("unit6_testinput_03.txt")
    expected = unit6utils.get_input_file("unit6_expectedoutput_03.txt")
    destination = unit6utils.get_temp_file("unit6_output_03.txt")
    anagram_sort(source, destination)
    result = [word.strip() for word in open(destination)]
    print result
    expected = [word.strip() for word in open(expected)]
    print expected
    assert expected == result
Пример #3
0
def test_anagram_sort():
    import sys
    print("sdv")
    print(sys.argv)
    source = unit6utils.get_input_file("unit6_testinput_03.txt")
    expected = unit6utils.get_input_file("unit6_expectedoutput_03.txt")
    destination = unit6utils.get_temp_file("unit6_output_03.txt")
    anagram_sort(source, destination)
    result = [word.strip() for word in open(destination)]
    expected = [word.strip() for word in open(expected)]
    assert expected == result
Пример #4
0
    l = list(filter(None, l))
    #print(l)

    for i in l:
        temp = []
        for j in l[l.index(i) + 1:]:
            if (sorted(i.lower()) == sorted(j.lower())):
                temp.append(j)
                l.remove(j)
        temp.append(i)
        temp.sort(key=lambda x: x.lower())
        res.append(temp)

    res.sort(key=lambda x: x[0].lower())
    res.sort(key=len, reverse=True)

    for i in res:
        for j in i:
            f2.write(j + '\n')
            print(j)


if __name__ == "__main__":
    x = input()
    z = x.split('.')
    z = z[0] + "-result.txt"

    destination = unit6utils.get_temp_file(z)
    anagram_sort(x, destination)

    #sys.exit(main())
Пример #5
0
def main():
    s = sys.argv[1] + ".txt"
    d = sys.argv[1] + "-results.txt"
    source = unit6utils.get_input_file(s)
    destination = unit6utils.get_temp_file(d)
    unit6_assignment_03.anagram_sort(source, destination)
    Main_words = [
        word.strip() + '\n' for word in sr_file.readlines()
        if word[0] != ' ' and word[0] != '#' and word[0] != '\n'
    ]
    while len(Main_words) != 0:
        words = Main_words
        I = Main_words[0]
        Anagram_dict[I] = [I]
        for word in words[1:]:
            if is_anagram(I.lower(), word.lower()):
                Anagram_dict[I].append(word)
                Main_words.remove(word)
        Main_words.remove(I)
    output = [
        tuple(sorted(x, key=lambda x: x.lower()))
        for x in Anagram_dict.values()
    ]
    output.sort(key=lambda x: x[0].lower())
    output.sort(key=lambda x: len(x), reverse=True)
    result = [word for Tuple in output for word in Tuple]
    ds_file.truncate()
    ds_file.writelines(result)
    ds_file.close()


if __name__ == "__main__":
    import unit6utils
    source = unit6utils.get_input_file("unit6_testinput_03.txt")
    destination = unit6utils.get_temp_file("unit6_output_03.txt")
    anagram_sort(source, destination)
    #sys.exit(main())
Пример #7
0
    b = map(number_char_product, a)
    i = 0
    j = 0
    t = []
    c = []
    try:
        while i < len(b):
            if b[i] == b[j]:
                t.append(a[j])
                j += 1
            else:
                c.append(t)
                t = []
                i = j
    except IndexError:
        c.append(t)
    c = [sorted(i, key=lambda x: x.lower()) for i in c]
    c = sorted(c,
               key=lambda x: (len(x), -number_char_product(x[0][0].lower())),
               reverse=True)
    with open(destination, 'w') as f:
        for s in c:
            for j in s:
                f.write(j + '\n')


if __name__ == "__main__":
    source = unit6utils.get_input_file(sys.argv[1])
    destination = unit6utils.get_temp_file(sys.argv[1][:-4] + '-results.txt')
    anagram_sort(source, destination)
    #sys.exit(main())