简体   繁体   English

Python从列表中切片元组

[英]Python slicing tuples from list

I need to extract the values 76212 & 160008 from my result which is below: 我需要从下面的结果中提取值76212160008

[(76212, 160008)]

For example I want: 例如我想要:

Result1 = 76212
Result2 = 160008

How do I achieve this? 我该如何实现?

EDIT Should probably add that this result is taken from SQLAlchemy ORM. 编辑可能应该补充一下,此结果取自SQLAlchemy ORM。 My code for this is below: 我的代码如下:

query1 = session.query(X.Y,Z.A) \
        .filter(cast(X.Y, VARCHAR).like(f'%{jobno}')) \
        .all()
    print(query1)

Assuming your result is named result: 假设您的结果命名为result:

result1, result2 = result[0]

For some more understanding, consider a tuple: 为了获得更多理解,请考虑一个元组:

x, y, z = (1, 2, 3)

>>x
1
>>z
3

It is not that complicated, but I guess you need to take some basic python course first. 它并不那么复杂,但是我想您需要先学习一些基本的python课程。 Before asking here on SO. 在这里问SO之前。

a = [(76212, 160008)]
Result1 = a[0][0]
Result2 = a[0][1]
result = [(76212, 160008)]
result1, result2 = result[0]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM