diff --git a/django/contrib/humanize/templatetags/humanize.py b/django/contrib/humanize/templatetags/humanize.py index d071c3a5be..bf30c43028 100644 --- a/django/contrib/humanize/templatetags/humanize.py +++ b/django/contrib/humanize/templatetags/humanize.py @@ -51,53 +51,53 @@ def intcomma(value, use_l10n=True): intcomma.is_safe = True register.filter(intcomma) -# A dictionary of standard large number to their converters -intword_converters = { - 6: lambda number: ( +# A tuple of standard large number to their converters +intword_converters = ( + (6, lambda number: ( ungettext('%(value).1f million', '%(value).1f million', number), ungettext('%(value)s million', '%(value)s million', number), - ), - 9: lambda number: ( + )), + (9, lambda number: ( ungettext('%(value).1f billion', '%(value).1f billion', number), ungettext('%(value)s billion', '%(value)s billion', number), - ), - 12: lambda number: ( + )), + (12, lambda number: ( ungettext('%(value).1f trillion', '%(value).1f trillion', number), ungettext('%(value)s trillion', '%(value)s trillion', number), - ), - 15: lambda number: ( + )), + (15, lambda number: ( ungettext('%(value).1f quadrillion', '%(value).1f quadrillion', number), ungettext('%(value)s quadrillion', '%(value)s quadrillion', number), - ), - 18: lambda number: ( + )), + (18, lambda number: ( ungettext('%(value).1f quintillion', '%(value).1f quintillion', number), ungettext('%(value)s quintillion', '%(value)s quintillion', number), - ), - 21: lambda number: ( + )), + (21, lambda number: ( ungettext('%(value).1f sextillion', '%(value).1f sextillion', number), ungettext('%(value)s sextillion', '%(value)s sextillion', number), - ), - 24: lambda number: ( + )), + (24, lambda number: ( ungettext('%(value).1f septillion', '%(value).1f septillion', number), ungettext('%(value)s septillion', '%(value)s septillion', number), - ), - 27: lambda number: ( + )), + (27, lambda number: ( ungettext('%(value).1f octillion', '%(value).1f octillion', number), ungettext('%(value)s octillion', '%(value)s octillion', number), - ), - 30: lambda number: ( + )), + (30, lambda number: ( ungettext('%(value).1f nonillion', '%(value).1f nonillion', number), ungettext('%(value)s nonillion', '%(value)s nonillion', number), - ), - 33: lambda number: ( + )), + (33, lambda number: ( ungettext('%(value).1f decillion', '%(value).1f decillion', number), ungettext('%(value)s decillion', '%(value)s decillion', number), - ), - 100: lambda number: ( + )), + (100, lambda number: ( ungettext('%(value).1f googol', '%(value).1f googol', number), ungettext('%(value)s googol', '%(value)s googol', number), - ), -} + )), +) def intword(value): """ @@ -124,7 +124,7 @@ def intword(value): template = float_formatted return template % {'value': value} - for exponent, converters in intword_converters.items(): + for exponent, converters in intword_converters: large_number = 10 ** exponent if value < large_number * 1000: new_value = value / float(large_number)