I'm trying to create a function that actually moves the items from one stack to another, however I have a lot of duplication. Can anyone help me refine it? (there is some bits that need to be added yet as well)
def guess2(frompeg, topeg):
temp = -1
if frompeg == 'a':
if a != []:
temp = a.pop()
else:
print('Error Popping a')
return ()
if frompeg == 'b':
if b != []:
temp = b.pop()
else:
print('Error Popping b')
return ()
if frompeg == 'c':
if c != []:
temp = c.pop()
else:
print('Error Popping c')
return ()
if topeg == 'a':
if a == []:
a.append(temp)
elif temp < a[-1]:
a.append(temp)
else:
print('Error')
if topeg == 'b':
if b == []:
b.append(temp)
elif temp < b[-1]:
b.append(temp)
else:
print('Error')
if topeg == 'c':
if c == []:
c.append(temp)
elif temp < c[-1]:
c.append(temp)
else:
print('Error')
print(a,b,c)
guess2('a','b')
print(a,b,c)