Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 11th, 2012  |  syntax: None  |  size: 0.99 KB  |  hits: 16  |  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. Python List Replace [closed]
  2. h = "2,3,45,6"
  3. h = h.replace(',','n')
  4. print h
  5.  
  6. Returns:
  7. 2
  8. 3
  9. 45
  10. 6
  11.        
  12. h = ["hello","goodbye","how are you"]
  13.  
  14. "hello"
  15. "goodbye"
  16. "how are you"
  17.        
  18. >>> h
  19. ['2', '3', '45', '6']
  20. >>> print 'n'.join(str(i) for i in h)
  21. 2
  22. 3
  23. 45
  24. 6
  25.        
  26. >>> h = ["hello","goodbye","how are you"]
  27. >>> print 'n'.join(str(i) for i in h)
  28. hello
  29. goodbye
  30. how are you
  31.        
  32. >>> h = ["hello","goodbye","how are you"]
  33. >>> print 'n'.join('"{0}"'.format(i) if isinstance(i,str) else str(i) for i in h)
  34. "hello"
  35. "goodbye"
  36. "how are you"
  37. >>>
  38.        
  39. >>> search = 'foo'
  40. >>> replace = 'bar'
  41. >>> lst = ['my foo', 'foo', 'bip']
  42. >>> print [x.replace(search, replace) for x in lst]
  43. ['my bar', 'bar', 'bip']
  44.        
  45. "".join([str(x) for x in h])
  46.        
  47. for each in h: print each
  48.        
  49. for each in h: print(each)
  50.        
  51. ['n' if x=="," else x for x in yourlist]
  52.        
  53. for item in list:
  54.     print item
  55.        
  56. s = "n".join([ "First", "Second" ])
  57.        
  58. l = ["xax", "xaax", "yayay" ]
  59. l = filter(lambda x: x.replace("a", "b"), l)
  60. print l
  61.        
  62. ['xax', 'xaax', 'yayay']