Still get string format problem on tesing "split_dataset_test"

I get this error on Week4 Lab

Cell #10. Can’t compile the student’s code. Error: TypeError(‘unsupported format string passed to list.format’)

And it seems like the error hasn’t been solved yet so I can’t pass my grade assignment. Anyone got the same problem?

Hi @Yushu_Guo, I suggest you to start investigating the problem this way: open the notebook on coursera, then on the menu bar, click “Kernel” > “Restart & Run All”. The code cells will start running one by one and when a cell is finished running, a number will show up on the L.H.S. of the cell. Follow the numbers until you reach number 10, based on the error message, it’s possible that you will find a print message that tries to print a list, or you will see additional error message under that code cell which tells you exactly which line has a problem.

Examine the line, and if this is about printing an unexpected list, it means that the variable it’s printing should have been other data type instead of a list, and then you may trace back to the source of error from there.

Hey, Rmwkwok. Thanks for the quick feedback! I have tried as you mentioned in the notebook. And I found this problem has been discussed in another problem - It’s the braket problem. Is this becuase it hasn’t been updated in the backend?

Here is the error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-10-bb920dab0f39> in <module>
     11 
     12 # UNIT TESTS
---> 13 split_dataset_test(split_dataset)

~/work/public_tests.py in split_dataset_test(target)
     70                 'right': np.array([2, 7, 9, 10])}
     71 
---> 72     assert np.allclose(right, expected['right']) and np.allclose(left, expected['left']), f"Wrong value when target is at index 0. \nExpected: {expected} \ngot: \{left:{left}, 'right': {right}\}"
     73 
     74 

TypeError: unsupported format string passed to list.__format__

Hey, @Yushu_Guo, the curely brackets problem has been reported and I believe the course team is aware of it, but they may have other priorities for now. Focusing on your code, if your code runs as expected, this curely brackets would not be triggered. One common cause of the error is that the code isn’t always only returning node_indices supplied to the split_dataset function. Sometimes learners would use range(len(node_indices)) but those are just enumerated integers starting from 0 instead of actually the content of node_indices - we need the latter.

Raymond

Looks like you have solved the problem. I am closing this thread.

1 Like