a = input().split('\n') b = input().split('\n') c = a.count(b) print(c)
时间: 2023-12-21 08:03:25 浏览: 104
c语言实现字符串分割split()
This code takes two inputs from the user, splits them into lists using the newline character as the delimiter, counts the number of times the second list appears in the first list, and then prints that count.
However, there is an issue with the code. The count() method expects a single argument, which is the element to be counted. In this code, the second input is being passed as the argument to count(), but count() is expecting a string or other object to count within the first list. Therefore, this code will raise a TypeError.
To fix this, we need to change the way we are using count(). One way to do this is to iterate over the first list and count the number of times the second list appears as a sublist. Here's an updated version of the code that does this:
a = input().split('\n')
b = input().split('\n')
c = 0
for i in range(len(a) - len(b) + 1):
if a[i:i+len(b)] == b:
c += 1
print(c)
阅读全文