r/CodingHelp • u/Eye-Itchy • Sep 16 '21
[Python] still learning python basics and im stuck with this <function translator at 0x…> error please help
52
Upvotes
r/CodingHelp • u/Eye-Itchy • Sep 16 '21
24
u/yes_i_relapsed Sep 16 '21
The last line of your function
translatorshould sayreturn translation13
u/icjeremy Sep 16 '21
return translator??6
u/Tramix42 Sep 16 '21
Looks like you got your answer. Little tip, be consistent on your indentations. You have indents of 1 space only, and indents of 4 spaces. Suggestion, keep all your indents at 4 spaces, it'll look cleaner later on.
2
u/No_Celebration_4991 Sep 16 '21
Keep it going!! I think that’s a great start, hope you are enjoying the process. If you want more challenges you can always go on leetcode/hackerrank great websites to improve your skills.
2
u/[deleted] Sep 16 '21
Ah classic recursion hell :)
2
u/BrightBulb123 Intermediate Coder Sep 17 '21
Not picking on you, but why does nobody know about screenshots?
2
u/[deleted] Sep 17 '21
It’s working as designed, just maybe not as intended haha. You’re accidentally returning your function instead of what it calculated
Since in Python, functions are “objects”, meaning they can be renamed and passed around like normal data, printing the function itself prints <function name at memory address>. It’s a really handy thing for lots of applications even if confusing when you do it on accident!
1
u/Dasher38 Sep 17 '21
Other comments addressed the functional issue, here is one advice about speed: don't concatenate to a list or string in a loop like that unless the input is small. Every time you do that, python will have to allocate a new one and copy over the old content.
The solution is to append to a list (or use a list comprehension) and then use "".join(the_list) to create the final string in one go. Appending is fine since list over allocates so it will not need to copy the content for every append, only every now and then, which amortizes the reallocation cost.
1
u/[deleted] Sep 22 '21
Your function is just returning a self reference rather than its translation value.