+ 2
How would you Count the errors in Python?
Hi Python lovers and Pythonism, could you please help me out with some coding in Python: Ok, I have a text file on my pc called date_time_pass_numbers.txt. In this file I have the following information like so: 16/06/2020 - 11:45:34, password < 6 14/06/2020 - 06:25:14, password < 6 11/06/2020 - 11:45:34, password > 10 12/06/2020 - 02:47:24, password < 6 10/06/2020 - 23:51:11, password > 10 Now my question is, How would I count the number of password < 6 and password > 10? For example I need to output the total number of password less than 6 separate and the total number of password greater than 10 separate, to the screen. How would I do this please?
1 Answer
+ 1
Quite easy with regex:
from re import findall
data = """16/06/2020 - 11:45:34, password < 6
14/06/2020 - 06:25:14, password < 6
11/06/2020 - 11:45:34, password > 10
12/06/2020 - 02:47:24, password < 6
10/06/2020 - 23:51:11, password > 10"""
print("< 6:", len(findall(r'password < 6', data))) # < 6: 3
print("> 10:", len(findall(r'password > 10', data))) # > 10: 2