简体   繁体   中英

Python slicing tuples from list

I need to extract the values 76212 & 160008 from my result which is below:

[(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. 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:

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. Before asking here on SO.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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