Using Reduce Method Javascript Substring In String In Python