Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def my_append(in_list, new):
- #Find the length of the list, splice it at that point and add the new data to the result
- in_list[my_len(in_list):] = [new]
- def my_extend(in_list, new):
- #Use append function on each item in new list
- #in_list doesn't play nice with my_len() because of how for loops index lists,
- #so it is stored in a temp list while the function is working
- for current in new:
- temp_list = my_append(in_list, current)
- in_list = temp_list
- def my_insert(in_list, place, new):
- #If adding to end of list just append it, otherwise use insert
- if place == my_len(in_list):
- my_append(in_list, new)
- else:
- #Split list into two lists at the index specified
- first_list = in_list[0:place]
- last_list = in_list[place:my_len(in_list)]
- #Add the new value at the end of the first half
- my_append(first_list, new)
- #Add first half (and new value) to second half
- my_extend(first_list, last_list)
- in_list[:] = first_list
- def my_len(in_list):
- #Loop through list and add one to total for each entry, then return total
- total = 0
- for current in in_list:
- total = total + 1
- return total
- def my_pop(in_list, place="unspecified"):
- #Set default for "place" to last index of list if unspecified
- if place == "unspecified":
- place = my_len(in_list) - 1
- #Store the popped value in a temp
- temp_mix = in_list[place:place + 1]
- #Remove the popped value from the list
- in_list[place:place + 1] = []
- #Return the popped value stored in the temp variable
- return temp_mix[0]
- def my_reverse(in_list):
- #Slice list backwards, python 2ez
- in_list[:] = in_list[::-1]
- test_list = [1,2,3]
- test_list[1:1] = 'x'
- print test_list
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement