I'm analyzing the code of this library and stumbled upon something unsusual in the decode_data
function.
def decode_data(data, fields, formats, decode_choices, scaling):
unpacked = formats.big_endian.unpack(bytes(data))
unpacked.update(formats.little_endian.unpack(bytes(data[::-1])))
return {
field.name: _decode_field(field,
unpacked[field.name],
decode_choices,
scaling)
for field in fields
}
More precisely, I do not understand the syntax of the return statement:
return {
field.name: _decode_field(field,
unpacked[field.name],
decode_choices,
scaling)
for field in fields
}
It looks to me like a reverse for loop, but I've never seen a similar notation elsewhere.
Also field.name:
written with the colon at the end does not make sense to me.
I know of lambda functions that use the colon notation, but the missing lambda statement points to something else.
Can someone explain to me what is going on here?
Thank you in advance.