0

I have a list of data and would like to print both "number" and "detail" on the same line. Currently the results print one after each other but I need the results to be on the same line.

for part in parts:

    number = part.text
    print(number)

for info in infos:

    detail = info.text
    print(detail)

Moving the print statement outside does not show all results, only the last result.

for part in parts:

    number = part.text

for info in infos:

    detail = info.text

print(number + detail)

How can I combine the data that is printed in these for statements?

mjbaybay7
  • 99
  • 5

1 Answers1

-1

Assuming parts and infos are of the same length:

for part,info in zip(parts,infos):
    print(part.text + info.text)

If one is shorter then the other, the extra items in longer one will be clipped off.

In that case, you may check itertools.zip_longest

fusion
  • 1,327
  • 6
  • 12