myObject = [('1', 'First'), ('2', 'Second')]
CHOICES = set(myObject)
def set_choices():
global CHOICES
CHOICES.clear() # Remove the element from set CHOICES
# Do some of your changes here
anotherObject = [('3', 'Third'), ('4', 'Fourth')]
CHOICES[:] = set(anotherObject)
print(CHOICES) # Before calling set_choices
set_choices()
print(CHOICES) # After you calling set_choices
I think this will work. But I don't know if using set and tuple is a good idea, I personally would suggestion you to use list of list instead. Are there particular reason to use a set instead of other options?
Output:
{('2', 'Second'), ('1', 'First')}
{('4', 'Fourth'), ('3', 'Third')}
Respond to your comment to use list:
CHOICES = [['1', 'First'], ['2', 'Second']]
def set_choices():
# Changed since the comment of another member aaronasterling
# Removed the use of global
CHOICES[:] = [['3', 'Third'], ['4', 'Fourth']]
print(CHOICES)
set_choices()
print(CHOICES)
Output:
[['1', 'First'], ['2', 'Second']]
[['3', 'Third'], ['4', 'Fourth']]
To learn more about slice assignment, check out this SO question & answer.