Hello i am doing my homework on coursera and the task is to build a sorting program that sorts numbers from least to greatest, the program seems to work fine until I run the test on it my code and error below.
def move_zero(lst):
"""
Given a list of integers, moves all non-zero numbers to the beginning of the list and
moves all zeros to the end of the list. This function returns nothing and changes the given list itself.
For example:
- After calling move_zero([0,1,0,2,0,3,0,4]), the given list should be [1,2,3,4,0,0,0,0] and the function returns nothing
- After calling move_zero([0,1,2,0,1]), the given list should be [1,2,1,0,0] and the function returns nothing
- After calling move_zero([1,2,3,4,5,6,7,8]), the given list should be [1,2,3,4,5,6,7,8] and the function returns nothing
- After calling move_zero([]), the given list should be [] and the function returns nothing
"""
# your code here
lst_join = ""
n_lst = lst_join.join(str(lst))
l = []
k = []
counter = 0
for i in (n_lst):
if i == ",":
continue
if i == "[":
continue
if i == " ":
continue
if i == "]":
continue
counter = counter + 1
l.append(int(i))
while len(k) != counter:
for n_num in l:
m_num = min(l)
k.append((m_num))
l.remove((m_num))
return k
lst = input("user input: ")
move_zero(lst)
mov = move_zero(lst)
print(mov)
and here is the error that I get when I run the test
---------------------------------------------------------------------------
AssertionError Traceback (most recent call last)
<ipython-input-24-7d2b0d5dd8e0> in <module>
4
5 lst = [0,1,0,2,0,3,0,4]
----> 6 assert_equal(None,move_zero(lst))
7 nose.tools.assert_list_equal([1,2,3,4,0,0,0,0],lst)
8
/opt/conda/lib/python3.7/unittest/case.py in assertEqual(self, first, second, msg)
850 """
851 assertion_func = self._getAssertEqualityFunc(first, second)
--> 852 assertion_func(first, second, msg=msg)
853
854 def assertNotEqual(self, first, second, msg=None):
/opt/conda/lib/python3.7/unittest/case.py in _baseAssertEqual(self, first, second, msg)
843 standardMsg = '%s != %s' % _common_shorten_repr(first, second)
844 msg = self._formatMessage(msg, standardMsg)
--> 845 raise self.failureException(msg)
846
847 def assertEqual(self, first, second, msg=None):
AssertionError: None != [0, 0, 0, 0, 1, 2, 3, 4]