程序填空题:jmu-python-重复数据判定
函数repeat(ls)判定列表ls中是否包含重复元素,如果包含返回True,否则返回False。每一个列表中只要有一个元素出现两次,那么该列表即被判定为包含重复元素。
然后使用该函数对n行字符串进行处理。最后统计包含重复元素的行数与不包含重复元素的行数。
# 输入格式:
输入n,代表接下来要输入n行字符串。
然后输入n行字符串,字符串之间的元素以空格间隔。
# 输出格式:
True=包含重复元素的行数, False=不包含重复元素的行数。
其中逗号后面有空格。
### 输入样例:
```in
5
1 2 3 4 5
1 3 2 5 4
1 2 3 6 1
1 2 3 2 1
1 1 1 1 1
```
### 输出样例:
```out
True=3, False=2
```
```python
def repeat(ls):
s=set(ls)
@@[if len(s)==len(ls):](3)
return False
else:
return True
n=int(input())
countT=countF=0
for i in range(n):
@@[if repeat(input().split()):](3)
countT+=1
else:
countF+=1
print(@@['True={}, False={}'.format(countT,countF)](4))
```
答案:
第1空:if len(s)==len(ls):
第2空:if repeat(input().split()):
第3空:'True={}, False={}'.format(countT,countF)
然后使用该函数对n行字符串进行处理。最后统计包含重复元素的行数与不包含重复元素的行数。
# 输入格式:
输入n,代表接下来要输入n行字符串。
然后输入n行字符串,字符串之间的元素以空格间隔。
# 输出格式:
True=包含重复元素的行数, False=不包含重复元素的行数。
其中逗号后面有空格。
### 输入样例:
```in
5
1 2 3 4 5
1 3 2 5 4
1 2 3 6 1
1 2 3 2 1
1 1 1 1 1
```
### 输出样例:
```out
True=3, False=2
```
```python
def repeat(ls):
s=set(ls)
@@[if len(s)==len(ls):](3)
return False
else:
return True
n=int(input())
countT=countF=0
for i in range(n):
@@[if repeat(input().split()):](3)
countT+=1
else:
countF+=1
print(@@['True={}, False={}'.format(countT,countF)](4))
```
答案:
第1空:if len(s)==len(ls):
第2空:if repeat(input().split()):
第3空:'True={}, False={}'.format(countT,countF)