Splitting input based on test cases

Asked by At

The problem I am working on says that the input is made up with a number of the test cases, and the word number, and the words x number of test cases.

For example:

    2
    3
    Potato
    Spud
    Baked
    2
    Fried
    Chicken

How would you split it between test cases?

I can't just use whitespace or a specific number, so is there like a regular expression or something similar?

msg = [string(msg) for msg in input().split()]  ]
for i in msg:
    count = str.count('c') + str.count('o') + str.count('d')

I should be able to see the number of times the letters c o d appear.

1 Answers

0
Mahmoud Elshahat On Best Solutions

Edit: first you should get your input() and store this input using while loop or whatever, then work on that input text, for example :

text = """
    2
    3
    Potato
    Spud
    Baked
    2
    Fried
    Chicken
"""
msg = text.split()
print(msg)
for i in msg:
    count = i.count('c') + i.count('o') + i.count('d')
    print('count for', i, '=', count)

output:

['2', '3', 'Potato', 'Spud', 'Baked', '2', 'Fried', 'Chicken']
count for 2 = 0
count for 3 = 0
count for Potato = 2
count for Spud = 1
count for Baked = 1
count for 2 = 0
count for Fried = 1
count for Chicken = 1