python - Python Problem: applied problem for building function for retrieving the elements from the list
问题描述
Problem: There is a marathon, and you have a list of the participants. (ex: ["jack", "mike", "john"]) The number of participants is random integer between 1 to 100000. You also have list of participants who completed the marathon. The number of the participants who completed is 1 less than the total participants. There could be participants who have same name. You have to build a function that would print the participant who didn't complete the marathon.
My attempt:
def solution(participant, completion):
for i in completion:
if i in participant:
participant.remove(i)
answer = print ('"' + str(*participant) + '"')
return(answer)
For example, if participant = ["john", "mike"], completion = ["john"], The expected answer is "mike" I think there is nothing wrong with the code I attempted. If there is, could you guys point out the part I missed? Most importantly, is there a more elegant way of building this function?
解决方案
for i in completion:
if i in participant:
participant.pop(i)
answer = print ('"' + str(*participant) + '"')
return(answer)
推荐阅读
- ios - 使用未解析的标识符“jpegData”
- java - 在 jsp 页面中打印 hashmap 值
- python - Python为未知行数绘制颜色
- python-3.x - 通过另一个字段 mongodb 查找不同的值组
- php - php 脚本根据产品值创建 csv 导出文件
- python - Python-pandas:一个序列的真值是模棱两可的
- ios - 无法重新解析位码包中的目标文件:'无效的位码版本
- php - 检查 PHP 上的 Mysql 数据库中是否存在值
- angular - 当应用程序在后台时,深层链接有效,但在被杀死时无效
- wordpress - Wordpress - 获取具有特定 ACF 值的帖子