Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
def position(position):
    position_piece = 2,2
    x,y = position
    if (x,y) == position_piece:
        return position_piece
    else:
        return None

print(position(2,2))


How can i put a tuple into a single argument like position? There has to be a way to do this without adding an argument. I need the argument position to be coordinate(x,y).

What I have tried:

Tried to use a second argument to see if the code works and it does, but im stuck if i try to run it with a single argument.
Posted
Updated 20-Nov-18 22:07pm
Comments
Afzaal Ahmad Zeeshan 21-Nov-18 3:36am    
You need to break the position that can be deconstructed as a tuple.

1 solution

You need to convert the argument from two numbers to a single tuple, by adding an extra set of parentheses thus:
Python
print(position((2,2)))
#              ^   ^
#              Extra parentheses make 2,2 into a single tuple.
 
Share this answer
 
Comments
CPallini 21-Nov-18 5:26am    
Indeed, 5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900