Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. ## apply same change to every element in a list
  2.  
  3. new_list = [x[10:] for x in old_list] # strip away the first 10 characters for every string in the old_list
  4.  
  5. ## Sorting
  6.  
  7. list.sort()
  8.  
  9. ## Get unique elements from a list x
  10.  
  11. unique_list = list(set(x))
  12.  
  13. ## Append an element to a list
  14.  
  15. list.append('New String')
  16.  
  17. ## Extend a list
  18.  
  19. list1.extend(list2) #the elements of list2 are added to the end of list1.
  20. list1 +=list2
  21.  
  22. ## replace characters in a string (e.g. substitute x with y)
  23. string.replace('x', 'y')
  24.  
  25. ##
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement