def main(intlist, value, index): intliststring = str(intlist)[1:len(str(intlist)) - 1] intlist = intliststring.split(", ") newlist = [] for each in intlist: newlist.append(int(each)) newlist.insert(index, value) return i.IntList(newlist)
def main(intlist, index, value): listarray = insertinmiddle(intlist, index) tmp = listarray[1].cons(value) for each in reversed(listarray[0]): tmp = tmp.cons(ilist.IntList(each)) return tmp
import intlist as ilist def insertinmiddle(intlist, index): count = 0 firsthalf = [] while count < index: firsthalf.append(intlist.first()) intlist = intlist.rest() count += 1 return [firsthalf, intlist] def main(intlist, index, value): listarray = insertinmiddle(intlist, index) tmp = listarray[1].cons(value) for each in reversed(listarray[0]): tmp = tmp.cons(ilist.IntList(each)) return tmp print(str(main(ilist.IntList([1,2,4,5]), 2, 3)))
import intlist n1 = intlist.IntList([2, 3, 4, 5, 6, 7]) # fulllist = [n1.first].append(n1.rest) def ithinkthishastoberecursive(n1): if(n1.nil == False): print(n1.first()) return ithinkthishastoberecursive(n1.rest()) else: return ithinkthishastoberecursive(n1)
import intlist as i def main(intlist, value, index): intliststring = str(intlist)[1:len(str(intlist)) - 1] intlist = intliststring.split(", ") newlist = [] for each in intlist: newlist.append(int(each)) newlist.insert(index, value) return i.IntList(newlist) print(main(i.IntList([1, 2, 4, 5]), 2, 3))