0

Sample data:

['2018-01-01','2018-01-02','2018-01-03','2018-01-04','2018-01-05',
 '2018-01-06','2018-01-07','2018-01-08','2018-01-09','2018-01-10',]

Expected output:

[['2018-01-01','2018-01-02','2018-01-03']
['2018-01-04','2018-01-05','2018-01-06']
['2018-01-07','2018-01-08','2018-01-09']
['2018-01-10']]

I tried triple-index slicing but it only keeps the start point and end point, excluding the values between them.

Pankaj
  • 931
  • 8
  • 15
Oldduck_
  • 1
  • 3

1 Answers1

0

You can use zip and make them all lists.

data = ['2018-01-01','2018-01-02','2018-01-03','2018-01-04','2018-01-05','2018-01-06','2018-01-07','2018-01-08','2018-01-09','2018-01-10',]

list(map(list, zip(*[data]*3)))

Output:

[['2018-01-01', '2018-01-01', '2018-01-01'], 
 ['2018-01-02', '2018-01-02', '2018-01-02'], 
 ['2018-01-03', '2018-01-03', '2018-01-03'], 
 ['2018-01-04', '2018-01-04', '2018-01-04'], 
 ['2018-01-05', '2018-01-05', '2018-01-05'], 
 ['2018-01-06', '2018-01-06', '2018-01-06'], 
 ['2018-01-07', '2018-01-07', '2018-01-07'], 
 ['2018-01-08', '2018-01-08', '2018-01-08'], 
 ['2018-01-09', '2018-01-09', '2018-01-09'], 
 ['2018-01-10', '2018-01-10', '2018-01-10']]
Pankaj
  • 931
  • 8
  • 15
Jab
  • 26,853
  • 21
  • 75
  • 114