Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2014
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.80 KB | None | 0 0
  1. def my_append(in_list, new):
  2.     #Find the length of the list, splice it at that point and add the new data to the result
  3.     in_list[my_len(in_list):] = [new]
  4.  
  5.  
  6. def my_extend(in_list, new):
  7.     #Use append function on each item in new list
  8.     #in_list doesn't play nice with my_len() because of how for loops index lists,
  9.     #so it is stored in a temp list while the function is working
  10.     for current in new:
  11.         temp_list = my_append(in_list, current)
  12.     in_list = temp_list
  13.  
  14.  
  15. def my_insert(in_list, place, new):
  16.     #If adding to end of list just append it, otherwise use insert
  17.     if place == my_len(in_list):
  18.         my_append(in_list, new)
  19.     else:
  20.         #Split list into two lists at the index specified
  21.         first_list = in_list[0:place]
  22.         last_list = in_list[place:my_len(in_list)]
  23.         #Add the new value at the end of the first half
  24.         my_append(first_list, new)
  25.         #Add first half (and new value) to second half
  26.         my_extend(first_list, last_list)
  27.         in_list[:] = first_list
  28.  
  29.  
  30. def my_len(in_list):
  31.     #Loop through list and add one to total for each entry, then return total
  32.     total = 0
  33.     for current in in_list:
  34.         total = total + 1
  35.     return total
  36.  
  37.  
  38. def my_pop(in_list, place="unspecified"):
  39.     #Set default for "place" to last index of list if unspecified
  40.     if place == "unspecified":
  41.         place = my_len(in_list) - 1
  42.     #Store the popped value in a temp    
  43.     temp_mix = in_list[place:place + 1]
  44.     #Remove the popped value from the list
  45.     in_list[place:place + 1] = []
  46.     #Return the popped value stored in the temp variable
  47.     return temp_mix[0]
  48.  
  49.  
  50. def my_reverse(in_list):
  51.     #Slice list backwards, python 2ez
  52.     in_list[:] = in_list[::-1]
  53.  
  54. test_list = [1,2,3]
  55. test_list[1:1] = 'x'
  56. print test_list
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement