I am new to Python. Have a question regarding join function.
masterlist = [
('ap172', ['33', '212-583-1173', '19 Boxer Rd.', 'New York', 'NY', '10005']),
('axe99', ['42', '212-582-5959', '315 W. 115th Street, Apt. 11B', 'New York', 'NY', '10027'])
]
I want to print each element of list delimited by pipe.
If I try:
for i in masterlist:
mystring = '|'.join(i)
print mystring
The error is:
TypeError: sequence item 1: expected string, list found
So I am trying:
for i in masterlist:
mystring = i[0]
mystring += '|'.join(i[1])
print mystring
and I get:
ap17233|212-583-1173|19 Boxer Rd.|New York|NY|10005
axe9942|212-582-5959|315 W. 115th Street, Apt. 11B|New York|NY|10027
So it works but would like to know if there is a better way to join the above masterlist using join function?