The dimensions of an a4 piece of paper are 8.5x11 inches, and the number of pixels which can fit inside these inches increases with dots per inch.
I made a Python list of tuples which expresses this as, using
>>> [(i,8.5*i,11*i) for i in range(18)]
which gives
[(0, 0.0, 0), (1, 8.5, 11), (2, 17.0, 22), (3, 25.5, 33), (4, 34.0, 44), (5, 42.5, 55), (6, 51.0, 66), (7, 59.5, 77), (8, 68.0, 88), (9, 76.5, 99), (10, 85.0, 110), (11, 93.5, 121), (12, 102.0, 132), (13, 110.5, 143), (14, 119.0, 154), (15, 127.5, 165), (16, 136.0, 176), (17, 144.5, 187)]
I then want to make a new list that contains only the factor by which the quantities in the first list grow, namely the sequence {0..18}.
But I want to do this by performing some operation on the first list. How can I do it?
选择每个元组的第一个元素:
[t[0] for t in originallist]
Or use the generator form to avoid materializing a list before you need it:
gen = (t[0] for t in originallist)
and when you need the list:
list(gen)
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.