pythonstringprintingconcatenationformatted-text

how to concatenate two formatted strings in python


Is there a way to concatenate these two formatted strings horizontally? I tried a + b but am having a vertically concatenated strings.

here is a screen shot of the formatted strings.

a =  '''
      __  
     (  ) 
      )(  
     (__) 
   '''
b = '''
    ____ 
   (  __)
    ) _) 
   (__) 
  '''
 print(a+b) #I don't need this I need horizontal way of concatenation

Solution

  • You can do something similar to this

    >>> lines = zip(a.split('\n'), b.split('\n'))
    >>> ab = '\n'.join([ai + bi for ai, bi in lines])
    >>> print ab
    
          __      ____ 
         (  )    (  __)
          )(      ) _) 
         (__)    (__) 
    
    >>>