Wednesday, July 19, 2017

Python-Printing the list elements on one line with comma separated

                This blog post is about printing the string values present in the list into a single line separated by a comma.

Input: [‘1’,’2’,’3’]
Output: 1, 2, 3

Code:
      #let us take a list with the elements ‘s’,’t’,’r’,’i’,’n’,’g’
      l=[‘s’,’t’,’r’,’i’,’n’,’g’]
      # now this is converted to our required format using the join function and
      # Below is the implementation

      print(‘,’.join(l))

Output:
                s,t,r,i,n,g