0

I have another question about somewhat the same problem as I had here -> Python double FOR loops without threading

Basically, I want the first for loop down here to enumerate over every school subject in a list, and then inside the print function, I want it to print every number that is in that list, so It comes out like 8 - 4 - 5 - 7 etc.

    for item in store:
        print(str(item + "|" + (str((cflist[i]) for i in range(3))) + "\n" + ("-------------" * 7)))
...
Running the complete code makes a big grid filled with these things, but different
subjects each line. (NTL here)
-------------------------------------------------------------------------------------------
NTL|<generator object <genexpr> at 0x0000000003404900>
-------------------------------------------------------------------------------------------

I have had the code working partially, so that each list number was in another subject line, so I would have NTL|8.2 and the next line ENT|5.7 But I want all those numbers to display after each other like NTL|8.2 - 5.7 - etc

EDIT: Done!

-------------------------------------------------------------------------------------------
NTL|7.2 8.4 6.7 5.3 4.8
-------------------------------------------------------------------------------------------

1 Answer 1

1

Using str on a generator expression will print str version of generator expression, not it's items as you expected:

>>> str((x for x in range(3)))
'<generator object <genexpr> at 0xb624b93c>'

Try something like this:

for item in store:
   strs = " ".join([cflist[i]) for i in range(3)])
   print(str(item + "|" + strs + "\n" + ("-------------" * 7)))
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you! It's working now. Now I need to make one of those for every subject line.
One more question, is there a way to make the for i in range(3) go in for i in range(all items in the list)?
@IPDGino You can also use " ".join(cflist), this will join all items of the cflist.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.