import socket
with open('urldict.txt', "rt") as file_in:
with open("newfile.txt", "w") as file_out:
for i in file_in:
host = i.strip()
file_out.write("%s [%s]" % (host, socket.gethostbyname(host)))
with open("newfile.txt", "w") as file:
for i in lines:
host = i.strip()
save = file.write("%s [%s]" % (host, socket.gethostbyname(host)))