I've been trying to find a way to print out a certain part of a dictionary's value, but haven't found what I'm looking for. Does anyone know if there is a way to print out one value? Similar to this:
rows["id"] = [1,2,3,4,5,6,7,8,9,10]
print(rows["id"(5)])
The second line doesn't work. Thanks.
what basically row is: it's a dictionary with 'id' as a key and then the list as the value of the key
rows = {"id":[1,2,3,4,5,6,7,8,9,10]}
rows['id'] = [1,2,3,4,5,6,7,8,9,10]
>>>rows['id'][5]
6
>>> rows['id'][:5]
[1, 2, 3, 4, 5]
hope it helps you to understand
Try this code
print(rows["id"][5])
First you select the value which corresponds to the 'id'
key (a list in this case). Then you select the value from the list using the index [5]
.
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.