The problem is in key=, you are passing a number when the expected should be a "function" or a lambda (as documented: https://docs.python.org/3/library/functions.html#sorted).
That is to say sorted tries to execute the value returned from alfabeto.get(i, ord(i)) as a function, but as alfabeto.get returns one of the values in:
{'t':0, 's':1, 'h':2, 'j':3, 'm':4, 'p':5, 'n':6, 'z':7, 'w':8, 'l':9, 'r':10, ' c':11, 'b':12, 'x':13, 'k':14, 'q':15, 'v':16, 'd':17, 'g':18, 'f':19}
Or take the amount ord(i) which is the alternative within the .get (see documentation: https://docs.python.org/2.4/lib/typesmapping.html) (I’m not sure, but this function I believe is only used in Python 2)
Have to be sure of exactly what you want to sort, an example of using the key=, supposing you want to compare the alfabeto.get with the current item generated by line.split:
sorted(line.split(), key=lambda lineitem: lineitem == alfabeto.get(i, ord(i)))
Seria similar to do this:
def comparacao(lineitem):
return lineitem == outrovaloracomparar
Then after the : in the lambda would be the same as the return
Note that the above codes are only examples, I don’t really understand what kind of condition you want to pass to ordering, the examples are just to understand how to use lambda or def with key=, then just adapt your need.
On what line exactly?
– David Alves
sorted = Sorted(line.split(), key=(alphabet.get(i, Ord(i))) nessa
– fernanda
Somewhere you redefined one of the functions of the line?
– Sam
What do you mean? ;-; .. ;-;
– fernanda