Ask your own question, for FREE!
Computer Science 44 Online
OpenStudy (anonymous):

question

OpenStudy (anonymous):

@shandelman

OpenStudy (anonymous):

hey @shandelman you know the question we did yesterday and we did the solution in one line and we just got def sort_by_value(dict1): print sorted(dict1, key=dict1.get) apparently its wrong :s

OpenStudy (anonymous):

like i know it works but the teachers answer replied with errors

OpenStudy (anonymous):

That's because you don't want to *print* the result, you want to *return* the result.

OpenStudy (anonymous):

would you mind looking at the error it gave back?

OpenStudy (anonymous):

test_2_sort_by_value ==================== Total tests: 4, passed: 0, failed: 1, had errors: 3 FAILURE: h u1 quellan csc108 exercises e3 repos e3 c2bhatti e3: test_2_sort_by_value.TestCases METHOD: test_2a_return_type Traceback (most recent call last): File "/h/u1/quellan/csc108/exercises/e3/tests/test_2_sort_by_value.py", line 32, in test_2a_return_type self.assertTrue(isinstance(result, list), msg) AssertionError: e3.sort_by_value should return a list, but returned type <type 'NoneType'>. ERROR: h u1 quellan csc108 exercises e3 repos e3 c2bhatti e3: test_2_sort_by_value.TestCases METHOD: test_2b_empty_dict Traceback (most recent call last): File "/h/u1/quellan/csc108/exercises/e3/tests/test_2_sort_by_value.py", line 41, in test_2b_empty_dict self.assertEqual(check_sorted(result, argument[i]) and check_all(result, argument[i]), True, msg) File "/h/u1/quellan/csc108/exercises/e3/tests/test_2_sort_by_value.py", line 8, in check_sorted for i in range(len(L)-1): TypeError: object of type 'NoneType' has no len() ERROR: h u1 quellan csc108 exercises e3 repos e3 c2bhatti e3: test_2_sort_by_value.TestCases METHOD: test_2c_typical_case Traceback (most recent call last): File "/h/u1/quellan/csc108/exercises/e3/tests/test_2_sort_by_value.py", line 52, in test_2c_typical_case self.assertEqual(check_sorted(result, argument) and check_all(result, argument), True, msg) File "/h/u1/quellan/csc108/exercises/e3/tests/test_2_sort_by_value.py", line 8, in check_sorted for i in range(len(L)-1): TypeError: object of type 'NoneType' has no len() ERROR: h u1 quellan csc108 exercises e3 repos e3 c2bhatti e3: test_2_sort_by_value.TestCases METHOD: test_2d_duplicates Traceback (most recent call last): File "/h/u1/quellan/csc108/exercises/e3/tests/test_2_sort_by_value.py", line 60, in test_2d_duplicates self.assertEqual(check_sorted(result, argument[i]) and check_all(result, argument[i]), True, msg) File "/h/u1/quellan/csc108/exercises/e3/tests/test_2_sort_by_value.py", line 8, in check_sorted for i in range(len(L)-1): TypeError: object of type 'NoneType' has no len()

OpenStudy (anonymous):

like thats what the teachers automated thing replied it back with

OpenStudy (anonymous):

Yeah, notice how it's expecting the function to return something, but it's returning NoneType? That's because your function isn't returning anything, it's just printing something to the screen, which is not the same thing. Replace the word "print" with the word "return".

OpenStudy (anonymous):

ooo thats all

OpenStudy (anonymous):

Yup.

OpenStudy (anonymous):

sickk alright this is another question i never asked you but i have a code for it could you tell me if i did it right

OpenStudy (anonymous):

Yup...you want to post it in a different question and close this one?

OpenStudy (anonymous):

alrightt

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!