Skip to content

Instantly share code, notes, and snippets.

def febo(length):
ll = []
if length == 0:
return ll
if length == 1:
ll.append(0)
return ll
@pharshal
pharshal / create new list from 2 lists
Created May 8, 2015 08:45
Write a function that combines two lists by alternatingly taking elements. For example: given the two lists [a, b, c] and [1, 2, 3], the function should return [a, 1, b, 2, c, 3].
def new_list(list1, list2):
list = []
for item1, item2 in zip(list1, list2):
list.append(item1)
list.append(item2)
return list
def sum(list):
if(len(list) == 0):
return
if(len(list) == 1):
return list[0]
return sum(list[:-1]) + list[-1]
def sum(list):
m = 0
g = 0
while(g < len(list)):
m = m + list[g]
g = g + 1
return m