Find Unique Characters in a File

前端 未结 22 2302
耶瑟儿~
耶瑟儿~ 2021-02-04 03:30

I have a file with 450,000+ rows of entries. Each entry is about 7 characters in length. What I want to know is the unique characters of this file.

For instance, if my f

22条回答
  •  粉色の甜心
    2021-02-04 04:01

    A very fast solution would be to make a small C program that reads its standard input, does the aggregation and spits out the result.

    Why the arbitrary limitation that you need a "script" that does it?

    What exactly is a script anyway?

    Would Python do?

    If so, then this is one solution:

    import sys;
    
    s = set([]);
    while True:
        line = sys.stdin.readline();
        if not line:
            break;
        line = line.rstrip();
        for c in line.lower():
            s.add(c);
    
    print("".join(sorted(s)));
    

提交回复
热议问题