Python return a linear/cumulative pairs of a list of numbers -


i have pandas dataframe has messy concatenation of many different tables. want segment these tables out , perform operations on them. have list of table header locations looks this: [1, 4, 5, 7, 9, 12, 15] - header of first table @ index 1, header of second table @ index 4, etc. goal use list slice dataframe , extract information each slice , munge data pretty.

i'm trying list of pairs this purpose: [[1,4], [4,5], [5,7], [7,9], [9,12], [12,15]]

i tried function, not quite returning want, returns pairs this: 1,4, 5,7, 9,12 - making me skip on every other table :/.

def pairwise(iterable): #this wrong     = iter(iterable)     return izip(a, a) 

am missing something? i'm going crazy here.

why not [[a[x], a[x+1]] x in range(len(a)-1)]? assuming a= [1, 4, 5, 7, 9, 12, 15]


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo