Jul-31-2018, 12:05 PM
(This post was last modified: Jul-31-2018, 12:09 PM by PreservedKillich.)
I am a C/C++ programmer (I have an inkling of classes and OOD) who has just been given his first Python task. My former co-worker who enjoyed code obfuscation wrote the following line of code:
event_arr = [x for x in _485_trace.split(" ") if x]
This is applied to a string with the format:
UC_COMMAND,bOptionalArg1,bOptionalArgN\n
where UC_COMMAND is an all uppercase string.
It has 0 or more positive int arguments, separated by a comma and exactly one blank (b) and terminated with a newline.
It looks to me like an array is being created and I infer from the brackets a list is being created on the fly. I think I understand the for clause but not the preceding 'x' nor the trailing 'if x'/
Your assistance would be much appreciated.
event_arr = [x for x in _485_trace.split(" ") if x]
This is applied to a string with the format:
UC_COMMAND,bOptionalArg1,bOptionalArgN\n
where UC_COMMAND is an all uppercase string.
It has 0 or more positive int arguments, separated by a comma and exactly one blank (b) and terminated with a newline.
It looks to me like an array is being created and I infer from the brackets a list is being created on the fly. I think I understand the for clause but not the preceding 'x' nor the trailing 'if x'/
Your assistance would be much appreciated.