Skip to content Skip to sidebar Skip to footer

Reconstruct Data From Dictionary Keys In Python

I'm reading data from a binary file that contains a dictionary as follows: a_dict = {'8a50b9f75b57104d89b58305d96045df':[b'\x94*\x08\x9d\xd8', 0, 1, 4, 6, 7], 'bff92f621cc65e2103

Solution 1:

Assuming that the bytes you need to con cat are the first elements of each list, then:

withopen(fname, 'rb') as f:
    bytes_list = []
    a_dict = pickle.load(f)
    for values_list in a_dict.values():
        file_bytes = values_list.pop(0)
        for Val in values_list:
            bytes_list.append((val, file_bytes[Val]))
Result = [byt for Val, byt insorted(bytes_list, key=lambda x: x[1])]

Sorry for probable compilation errors, I'm on my phone

Post a Comment for "Reconstruct Data From Dictionary Keys In Python"