Compare length of two strings: Difference between revisions

Content added Content deleted
Line 1,041: Line 1,041:
===Advanced solution===
===Advanced solution===
{{works with | Python | 3.8}}
{{works with | Python | 3.8}}

The solution below has some imperfection. When the longest strings of characters are of equal length, instead of describing them as "''one of the longest''" they are described as "''the longest''". This works similarly for the shortest strings. Also, if all strings (in this case where there is only one) have the same length it is not printed that they are the shortest strings. Of course, this could be improved.

<lang Python>"""
<lang Python>"""
An example code for the task "Compare length of two strings" (Rosseta Code).
An example code for the task "Compare length of two strings" (Rosseta Code).
Line 1,084: Line 1,087:
lengths_and_objects = zip(lengths, objects)
lengths_and_objects = zip(lengths, objects)


# Longer phrases make translation into other natural languages easier.
# Longer phrases make translations into other natural languages easier.
#
#
has_length = _('has length')
has_length = _('has length')