Sep-21-2022, 12:16 PM
(This post was last modified: Sep-21-2022, 02:54 PM by Larz60+.
Edit Reason: Added output tags (good for input as well as output)
)
I have the following text file:
For example:
Here is my code:
Output:S = 0, X are: (1, 0, 1, 1, 0, 0, )S = 0, Z are: (0, 1, 1, 1, 0, 1, )Data bits measurement:0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, Measured l0: 1, Measured l1: 0
S = 0, X are: (1, 1, 0, 0, 0, 1, )S = 0, Z are: (1, 1, 0, 0, 1, 1, )Data bits measurement:1, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, Measured l0: 0, Measured l1: 1
S = 0, X are: (1, 1, 0, 0, 1, 1, )S = 0, Z are: (1, 1, 0, 0, 1, 1, )Data bits measurement:1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, Measured l0: 1, Measured l1: 0
S = 0, X are: (1, 1, 1, 0, 1, 1, )S = 0, Z are: (0, 0, 0, 1, 0, 0, )Data bits measurement:0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 0, 1, 0, Measured l0: 1, Measured l1: 0
S= 0, X are: (1, 1, 0, 1, 1, 0, )S = 0, Z are: (0, 0, 0, 1, 0, 0, )Data bits measurement:0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, Measured l0: 1, Measured l1: 0
S = 0, X are: (1, 1, 0, 0, 1, 1, )S = 0, Z are: (1, 1, 1, 0, 0, 1, )Data bits measurement:1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, Measured l0: 1, Measured l1: 0
Now, I want to count how many same Z value I have and I have many l0 I have for this Z value:For example:
Output:011101 - 1 and l0 1 (in total)
110011 - 2 and l0 1 (in total)
000100 - 2 and l0 2 (in total)
111001 - 1 and l0 1 (in total)
I thought regex can be nice but I could not manage to use it:Here is my code:
with open("f.dat") as file: lines = file.readlines() #Z=re.search("(^Z*)",line) for i in re.findall(r'Z are: (=(\d+)&',lines): print(i)And I got this error:
Error:raise source.error("missing ), unterminated subpattern",
re.error: missing ), unterminated subpattern at position 17