News

Day 13 Hints; eval()

Written on 13.12.2022 11:50 by Sven Rahmann

Good morning!

I hope you all have a wonderful day. Let's make the most of today and tackle whatever challenges come our way.

Today's problem (day 13) requires you to write a comparison(x1, x2) function. It will probably have to be recursive. Read the instructions and the example very carefully! This is easy to get wrong.

One concrete hint for reading the input: You will have a string that represents a Python list, like "[1,2,3]". To get the actual list object, you can pass the string to the eval() function, which evaluates an arbitrary string as a Python expression. Careful! Never do this with untrusted user input ("eval is evil"):

L = eval("[1,2,3]") will give you the list [1,2,3]

Note that the same trick can also be applied on day 11, where you have strings like '  Operation: new = old + 6'. If you split this at '=', take the right part and prepend 'lambda old:' and eval this like f = eval('lambda old: old + 6'), then f will be an actual Python function that adds 6 to its input argument, and you can actuall call f(17) to get 23.

Remember to stay focused and stay positive, and you can accomplish anything. Have a great day!

 

Privacy Policy | Legal Notice
If you encounter technical problems, please contact the administrators.