with open("record_types.txt", "r") as f: data = f.read() GROUPING = 3 PREFIX = "RT_" line = [] out = "" for i, l in enumerate(data.split("\n")): word = l.strip() #bytes_ = [ord(c) for c in word] #le_hex = "".join([hex(c)[2:] for c in reversed(bytes_)]) #line += [f"0x{le_hex}u"] line += [f"[{PREFIX}{word}] = {word}"] if (i + 1) % GROUPING == 0: out += ", ".join(line) + ",\n" line = [] if line: out += ", ".join(line) + ",\n" print(out)