View Single Post
Old 01-30-2022, 09:25 AM   #12
capink
Wizard
capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.
 
Posts: 1,203
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
Quote:
Originally Posted by chaley View Post
I looked at that code at least 20 times before I saw it.
I don't understand what re.sub() would fix. The dict comprehension on line 5 ensures that the key starts with the user_cat_prefix so removing len(user_cat_prefix) characters from the key (user_cat) can't do the wrong thing. What am I missing?
It will not change much. It only fails better in case the user enters a wrong value for user_cat_prefix (e.g missing one or more letters), it will return the full path of the user category, which makes it more obvious what the user did wrong.
capink is offline   Reply With Quote