Error in UNQ_Q2

I am getting the following error in the second problem (UNQ_Q2), which I cannot seem to debug.

ord() expected string of length 1, but int found

Note that the ord() function mentioned above is from the previous problem in this assignment (function ‘line_to_tensor’ of UNQ_Q1) which I correctly coded and it passed all the tests. Interestingly when called from within UNQ_Q2 it runs into the above issue. I suspect this is related to the fact that when a string of numbers is passed to ‘line_to_tensor’ then, when it breaks the sequence to individual elements – ord() gets a number rather than a character as its argument (while it expects a character). Re-coding ‘line_to_tensor’ to “force” the ord() function to take a string (using the str() function) still did not help. Any help will be much appreciated.

The first time you use line_to_tensor function in UNQ_C2 you do in a for loop (li is a line in a batch).

If you want to catch a bug like that, I would suggest to check what do you pass to line_to_tensor function either by “printing” it out with it’s “type” or using debug tools like breakpoint() or other ways. For example, if you know that at first iteration of the loop the li variable is “abcdefg or whatever” you could pass it to line_to_tensor separately (in a new jupyter notebook cell) to check it’s behavior.

Thank you for your response but unfortunately that is not answering my question. It was understandable that line_to_tensor is being used within a for loop in UNQ_Q2 (that’s how the code appears in the exercise to start with). Once again, the line_to_tensor works well and passes all the tests in UNQ_Q1. Its use for UNQ_Q1 is what causes the issue, when used within the for loop (line_to_tensor(li)).

Any constructive feedback will be appreciated.

As I said, you need to know what li value is first. Can you print it out and check?

Hi @Davit_Khachatryan

Did you solve the problem?

Thanks for following up. Yes, and it was a careless error on my part, in fact unrelated to the line_to_tensor function. I had made an error initializing the batch variable.