python - 打印列表中所有目标出现的索引的函数
问题描述
我被困在一个问题上:
编写一个函数,打印项目中所有出现的print_matching_indexes(items, target)
索引。我们使用 for 循环来迭代列表target
list
我已经写了:
def print_matching_indexes(items, target):
"""Prints the indexes of all (target) in the list (items)"""
for i in items:
print (items.index)
但我收到消息:
<built-in method index of list object at 0x7fc8103caa00>
<built-in method index of list object at 0x7fc8103caa00>
<built-in method index of list object at 0x7fc8103caa00>
如果它有效,则以下测试代码应导致:
pets = ['dog', 'cat', 'fish', 'cat', 'dog', 'iguana']
print_matching_indexes(pets, 'cat')
结果
1
3
我要去哪里错的任何指示?
解决方案
推荐阅读
- flutter - Flutter TextFormField inpy边框颜色不改变
- java - 编译时的 Gradle 依赖问题
- azure - 当(Azure)databricks 运行时版本更改时,pyspark join 失败
- javascript - Vue 减少了 fusioncharts 和 apexcharts 的包大小
- reactjs - 尝试在 MERN 堆栈中创建新项目时,出现 TypeError: this.props.meals.map is not a function
- spring-integration - 如何在 MailSendingMessageHandler 中检查邮件发送是否成功
- c# - 在 C# 中模拟抢占式调度机制
- amazon-web-services - 是否可以将 CodeBuild CloudWatch 日志发送到 slack?
- python - 使用一个for循环PYTHON计算欧几里得距离矩阵
- c++ - 类中联合的默认初始化