Mega Code Archive

 
Categories / Python / String
 

Split and join

s = "this   is\na\ttest"                           print s  print s.split()                                     print " ".join(s.split())                           # split without any arguments splits on whitespace.  # You can normalize whitespace by splitting a string with split and then  # rejoining it with join, using a single space as a delimiter.  # This is what the info function does to collapse multiline doc  # strings into a single line.