Q:

how to split file lines based on comma and concatenate new string

I have a file which has lines like below,
Files are in /tmp/file
            cat /tmp/file
            server1,server2
            server4,server4

I want to concatenate each line to new word ".com" so it will look like below.
When i covert this and split it doesn't work , Please guide
        newfile = server1.com,server2.com
                  server3.com,server4.com

            with open('/tmp/file', 'r') as file1:
                   newline = ''
                   for line in file1:
                       y = line.split()
                       print(y)
                   for line in y:
                       z = str(y).split(',')
                       print(z)
                       newline = str(z)+".com".join('' )
                   print(newline)

Results :
            ['server1,server2']
            ['server3,server4']
            ["['server3", "server4']"]
            ["['server3", "server4']"]

Expected :
                server1.com,server2.com
                server3.com,server4.com

A:

with open('/tmp/file', 'r') as r:
    for line in r:
        newline = line.strip()
        newline = newline.split(',')
        for i in range(len(newline)):
            newline[i] = newline[i] + ".com"
        newline = ",".join(newline)
        print newline

This code can be optimized a lot. But this is for better understanding

