Reputation: 111
I'm trying to create a tuple where each element is a slice, but the slice values depend on its position in the tuple. For example:
sl = (0.1,0.2,0.3)
for i in range(3):
slic = slice(0,sl(i),0.1) if i==0 else slice(sl(i-1),sl(i),0.1)
In this way, I can make the slices I want for every i
. Now, how can i create a tuple concatenating with all these values? i.e., the first element of the tuple will correspond to slic
for i =0
, and so on... Thank you for the comprehension.
Upvotes: 0
Views: 169
Reputation: 44838
You can use a generator expression:
tuple(
slice(0, sl[i], 0.1) if i==0 else slice(sl[i-1], sl[i], 0.1)
for i in range(3)
)
Upvotes: 1