How to make a Python set case insensitive? [duplicate]

青春壹個敷衍的年華 提交于 2021-02-10 14:58:39

问题


I have the following script to import and export random TXT/CSV files from CLI, everything that passes has to be unique and case insensitive output in UTF-8, can I accomplish this with a set variable? I'm quite new to Python so every comment or suggestion is welcome!

This is my current script;

import hashlib
import sys


if len(sys.argv) < 3:
    print("Wrong parameter; script | inputfile | outputfile")
    sys.exit(1)

output_file_path = (sys.argv[2])
input_file_path = (sys.argv[1])

completed_lines_hash = set()

output_file = open(output_file_path, "w")

for line in open(input_file_path, "r")

  hashValue = hashlib.md5(line.rstrip().encode('utf-8')).hexdigest()

  if hashValue not in completed_lines_hash:
    output_file.write(line)
    completed_lines_hash.add(hashValue)

output_file.close()

来源:https://stackoverflow.com/questions/53780519/how-to-make-a-python-set-case-insensitive

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!