Input: ['a','b','c','d','e']
Output: [('a','b'),('c','d'),('e')]
How can I do it in 1 or 2 lines of code ?
For the moment I have this:
def tuple_list(_list):
final_list = []
temp = []
for idx, bat in enumerate(_list):
temp.append(bat)
if idx%2 == 1:
final_list.append(temp)
temp = []
if len(temp) > 0: final_list.append(temp)
return final_list
tuple_list(['a','b','c','d','e'])