I'm have a script that takes data and essentially cleans it by removing nominal-only elements. I'm wondering how I can adjust remove='^[0-9.]+$' to start at a specific index, let's say index 4? Right now it sweeps through each index.
def split_lines(fp, delimiter, remove='^[0-9.]+$'):
with open(fp, mode="r", encoding="utf-8") as file:
clean_list = []
for line in file:
tokens = line.split(delimiter)
tokens = [re.sub(remove, "", token) for token in tokens]
clean_list.append(list(filter(lambda e: e.strip(), tokens)))
txt_edit.delete("1.0", tk.END)
unique_data = {}
for item in clean_list:
key = str(item)
if not unique_data.get(key):
unique_data[key] = 1, item
else:
unique_data[key] = (unique_data[key][0] + 1), item
for k, v in unique_data.items():
txt_edit.insert(tk.END, f"{v[1]}x {v[0]} \n")