use a function to replace ifelse stmt when fetching value from dict