QuestionQ54

Miscellaneous (List Comprehensions, Lambdas, Closures, I/O)

What is the expected result of this code?

mytu = ('a', 'b', 'c')  
m = tuple(map(lambda x: chr(ord(x) + 1), mytu))  
print(m[-2])  
  • A an exception is raised
  • B a
  • C b
  • D c
Explanation

Applying chr(ord(x) + 1) advances each character by one code point, producing ('b', 'c', 'd'). Negative index -2 selects the second-to-last element, which is c.

Community Discussion

No comments yet. Be the first to start the discussion!