[Answer]-How to convert python list[a,b,c,d] to [a:b, c:d] format

1👍

First of all let’s get the terminology straight – that’s not a Python list, it’s an array with two dimensions. You’re trying to do a slice on it.

cropped = bimage[cropDim[0]:cropDim[1], cropDim[2]:cropDim[3]]

0👍

k so lets play the guessing game with good assumption 🙂
as per the heading it says how to convert python list[a,b,c,d] to [a:b, c:d] format:

so we will assume cropDim = [a,b,c,d] and output required is [a:b,c:d]

cropDim = [a,b,c,d]
templist1 = []
templist2 = []
for i,item in enumerate(cropDim):
    if i % 2 ==0:
        templist1.append(item)
    else:
        templist2.append(item)
result = map(':'.join,zip(templist1,templist2))
print result #behold the power of assumption
👤hemraj

Leave a comment