This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on May 8th, 2013  |  syntax: None  |  size: 0.68 KB  |  views: 1,359  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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']
clone this paste RAW Paste Data