I have an input.txt file.
Information: The file 'U_1A/U_2A/U_3C/U_4D' will be found (TBD-001)
Information: The file 'U_1A/U_2A/U_3C/U_4D' will be found (TBD-001)
Information: The file 'U_1A/U_2A/U_3C/U_4D' will be found (TBD-001)
Information: The file 'U_1A/U_2B/U_3C/U_4D' will be found (TBD-001)
Information: The file 'U_1A/U_2C/U_3C/U_4D' will be found (TBD-001)
Information: The file 'U_1A/U_2C/U_3C/U_4A' will be found (TBD-001)
Information: The file 'U_1B/U_2A/U_3C/U_4B' will be found (TBD-001)
Information: The file 'U_1B/U_2B/U_3C/U_4D' will be found (TBD-001)
Information: The file 'U_1C/U_2B/U_3C/U_4A' will be found (TBD-001)
Information: The file 'U_1C/U_2B/U_3C/U_4D' will be found (TBD-001)
what I really want to do is counting the number of contents inside the single quote in descending order.
So, When I execute the python code, User should put certain number. and that input number means the depth of the hierarchy. for example, When I put 2, then the output should be like this
U_1A/U_2A : 3
U_1A/U_2C : 2
U_1C/U_2B : 2
U_1A/U_2B : 1
U_1B/U_2A : 1
U_1B/U_2B : 1
and when I put 3, the output be like this.
U_1A/U_2A/U_3C : 3
U_1A/U_2C/U_3C : 2
U_1C/U_2B/U_3C : 2
U_1A/U_2B/U_3C : 1
U_1B/U_2A/U_3C : 1
U_1B/U_2B/U_3C : 1
so on so forth.
In order to achieve this, I managed to sort out the list of the string inside '' by the following code.
text = open("input.txt", "r")
# Loop through each line of the file
for line in text:
# Remove the leading spaces and newline character
line = line.strip()
#print(line)
# Split the line into words
words = line.split(' ')
word = words[3]
print (word)