Python Build a chatbot skillpath. GENERATIVE CHATBOTS lesson, exrcise 2 Choosing the Right Dataset

Exercise don’t accept the print statement!
When i run code withh added line
print(dialog_combos)
I can see dialog_combos printed to the console, but test not pass, saying
“Expected all dialog_combos to be printed out.”
Please, help!!!

1 Like

Welcome to the forums! :slight_smile:

Would love to help.

Can you post the rest of your code? (remember to format it with </> button)

Hello and thank you!

Here is the code:

import more_itertools as mit

data_path = "pb.txt"

# Defining lines as a list of each line
with open(data_path, 'r', encoding='utf-8') as f:
  raw_lines = f.read().split('\n')

raw_lines.reverse()
lines = []

for line in raw_lines:
    # split line into parts
    line_split = line.split(' +++$+++ ')
    # append tuple of character and line
    line_num = int(line_split[0][1:])

    current_line = line_split[4].strip()
    # append tuple of line num, character and line
    lines.append((line_num, current_line))
# make sure the lines are in order
lines = sorted(lines, key=lambda x: x[0])

# group lines by scene
by_scene = [list(group) for group in mit.consecutive_groups(lines, lambda x: x[0])]

dialog_only = [[dialog_line[1] for dialog_line in dialog_group] 
                for dialog_group in by_scene]

dialog_combos_nested = [list(map(list, zip(dialog_group, dialog_group[1:]))) for dialog_group in dialog_only]

dialog_combos = [combo for combos in dialog_combos_nested for combo in combos]

# print dialog combos:
print(dialog_combos)

When i run it it says:
Expected all dialog_combos to be printed out.
error =(

This is the exercise

I can see two possibilities:

  • the validator doesn’t like the formatting (which I’ll ignore for now)
  • there’s something you code is not catching from the txt, so you are printing but there’s a dialog combo you’re not getting.

If you check out the txt you can probably get a better idea about what combos are missing and how you have to tweak your code to get it.

All this code was written at the start of exercise, it’s not my code… All I had to do, according the only instruction, place a simple print statement, but it doesn’t work… I figured out that dialog_combos_nested variable skip single lines of the dialogs, so dialog_combos really doesn’t content all the lines. But anything I do can’t satisfy the validator anyway…

It sounds like it might be stuck on a very specific detail. You can always check the solution (it’ll validate the exercise) and see if it was just a simple thing. If it was anything bigger you can always reset the exercise and try again.

As for me to check the solutions seems to cheat, and i don’t like cheating… Anyway i can’t see a possible solve for this situation. I checked the solution. The solution is the very same code that i tried hundred times - just print(dialog_combos) statement in the end of file, which printed the very same stuff as i tried it before. The only difference - “Next” button finally yellow and i can move on… Seems unfair make people cheat just because of real bug…
Anyway thanks a lot!

Oh I agree. I just don’t think of it as cheating. Cheating is when it’s a real issue.

Now there’s something to be said about the specificity required in programming (being case-sensitive, no extra spaces, etc.), but after 5 minutes of it I think we get the point. There are for sure bigger fish to fry :fishing_pole_and_fish: :fire:

Next exercise - the very same situation! In the last task i had to make a simple print statement and again it cannot satisfy the validator… I checked the solution, copy-pasted all the code to reseted workspace, and… It doesn’t work… This lesson seems to be mad on print statements… Really broken…

1 Like

I’ll see if people know anything about this issue. Thanks for calling it to attention!