Updated python program to use a lambda function