Advertisement
Guest User

Untitled

a guest
May 8th, 2013
10,872
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. ['xxxxxxn', 'xxxxxxn', 'xxxxxxn', 'xxxxxxn', 'xxxxxx n', 'xxxxxxn',
  2. ' xxxxxx n', 'xxxxxx n', 'xxxxxxn', ...]
  3.  
  4. AttributeError: 'list' object has no attribute 'strip'
  5.  
  6. [s.strip().title() for s in my_list]
  7.  
  8. a = ['xxxxxxn', ' xxxxxx n', 'xxxxxx n', 'xxxxxxn', ...]
  9. a = [x.strip().title() for x in a]
  10.  
  11. my_list=['xxxxxxn', 'xxxxxxn', 'xxxxxxn', 'xxxxxxn', 'xxxxxx n', 'xxxxxxn', ' xxxxxx n', 'xxxxxx n', 'xxxxxxn']
  12.  
  13. def format_string_from_list(_str):
  14. return _str.strip().title()
  15.  
  16. my_new_list=[format_string_from_list(_str) for _str in my_list]
  17. print my_new_list
  18.  
  19. >>> ['Xxxxxx', 'Xxxxxx', 'Xxxxxx', 'Xxxxxx', 'Xxxxxx', 'Xxxxxx', 'Xxxxxx', 'Xxxxxx', 'Xxxxxx']
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement