-1

I am running the following block of code:

def update_contact_number(contacts, contact_name, old_number, new_number):
    if contact_name in contacts:    
        lis = list(contacts[contact_name].values())
        lis[0]=new_number
        contacts[contact_name].values()=tuple(lis)
        return True
    else:
        return False

when I get this error:

SyntaxError: can't assign to function call.

Can anyone come up with a solution and the possible problem?

Miraj50
  • 4,257
  • 1
  • 21
  • 34
Shubham
  • 21
  • 1
  • 2
  • 9

1 Answers1

4

The line:

contacts[contact_name].values()=tuple(lis)

Is not syntactically correct.

As to how to achieve what you want... you did not state what you want so nobody can help you.

It seems like you want to change the number of a contact, but then I don't understand why contacts[contact_name] would be a dict. Also note that if this is true:

lis[0]=new_number

Here lis[0] is basically a random value contained in that dictionary, because the order of the keys and values of a dictionary is undefined.

Bakuriu
  • 98,325
  • 22
  • 197
  • 231
  • Not random, but [arbitrary](http://stackoverflow.com/q/2860339/). – Ignacio Vazquez-Abrams Jan 17 '14 at 09:53
  • @IgnacioVazquez-Abrams Well, since in last versions of python there's hash randomization it is indeed random. It is arbitrary only during a *single* execution of the program but running the program multiple times can give different results. – Bakuriu Jan 17 '14 at 09:55
  • What help I was seeking for is looking for tips on why the code was not working. The error language is too cryptic to make out. The dictionary and the order was defined as a global variable. I just posted the snippet which was having bugs. You got it right, Thanks! – Shubham Jan 18 '14 at 21:46