SHARE
TWEET

Untitled

a guest May 8th, 2013 3,262 Never
  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']
RAW Paste Data
Top