python - 如何在数组/列表中按索引查找值?
问题描述
如果数组是['VyJXcp', 'https://google.com']
,我如何通过索引获取“https://google.com”?
我尝试了以下方法:
@app.route('/<id>')
def redirect(id):
target = Shrtn.query.filter_by(key=id).all()
target2 = target[1]
return str(target2)
和 Shrtn.query.filter_by(key=id).all() 结果很好(上面粘贴的那个),当我这样做时,return str(target)
它确实有效,但是当我使用return str(target2)
它时,我得到一个 IndexError;IndexError: list index out of range
返回正确字符串的正确方法是什么?
解决方案
如果数组是 ['VyJXcp', 'https://google.com'] 所以
arr = ['VyJXcp', 'https://google.com'] ?
我怎样才能通过索引获得“https://google.com”
arr[1]
结果是
Out[11]: 'https://google.com'
推荐阅读
- c# - 如何通过 azure relay C# 发送 prem wcf https 服务的基本身份验证凭据?
- python - 在for循环中定义可变列数
- python - SyntaxError:关键字不能是表达式(将行与表达式匹配)
- python - 将光标的焦点设置回 Python
- python - Z3Prover 中的女士或老虎问题
- installation - 哪个 protobuf 版本与 caffe 一起使用?
- graphics - 球对球碰撞解决方案
- javascript - 光标位于带有 React 的自动聚焦文本区域的开头
- c# - 使用反序列化 XML 文件中的多字段 List<> 填充第二个单字段列表 (Xamarin)
- java - JSON 在全选中抛出 java.lang.StackOverflowError