Home > Software engineering >  I have a list of nested tuples. [(('employment', 'agency'), 8055), (('track
I have a list of nested tuples. [(('employment', 'agency'), 8055), (('track

Time:10-02

[(('employment', 'agency'), 8055),  (('track', 'record'), 5472)]

I want help to convert this in the format:

employment agency, 8055
track record, 5472

and store this output as a text file.

Thanks in advance :)

CodePudding user response:

Try:

lst = [(('employment', 'agency'), 8055), (('track', 'record'), 5472)]
output = '\n'.join(' '.join(x[0])   ', '   str(x[1]) for x in lst)
print(output)

# output:
# employment agency, 8055
# track record, 5472

I doubt this needs further explanation. Just note that join is helpful in this kind of situation.

  • Related