Compare length of two strings: Difference between revisions

Content added Content deleted
Line 367: Line 367:
lengths and classification as the longest, shortest or average length.
lengths and classification as the longest, shortest or average length.


Note that for N > 0 such objects (e.g., strings, byte strings, lists) it is
Note that for N > 0 such objects (e.g., strings, bytes, lists) it is
possible that exactly M > 0 of them will be of the maximum length, K > 0 of
possible that exactly M > 0 of them will be of the maximum length, K > 0 of
them will be of the minimum length. In particular, it is possible that all
them will be of the minimum length. In particular, it is possible that all
Line 393: Line 393:
# Longer phrases make translation into other natural languages easier.
# Longer phrases make translation into other natural languages easier.
#
#
has_length = _('has length')
if all(isinstance(obj, str) for obj in objects):
if all(isinstance(obj, str) for obj in objects):
predicate_max = _('is the longest string')
predicate_max = _('and is the longest string')
predicate_min = _('is the shortest string')
predicate_min = _('and is the shortest string')
predicate_ave = _('is neither the longest nor the shortest string')
predicate_ave = _('and is neither the longest nor the shortest string')
else:
else:
predicate_max = _('is the longest object')
predicate_max = _('and is the longest object')
predicate_min = _('is the shortest object')
predicate_min = _('and is the shortest object')
predicate_ave = _('is neither the longest nor the shortest object')
predicate_ave = _('and is neither the longest nor the shortest object')


if sorted_:
if sorted_:
Line 412: Line 413:
else:
else:
predicate = predicate_ave
predicate = predicate_ave
print(f'"{obj}" has length {length} and {predicate}')
print(obj, has_length, length, predicate)




Line 428: Line 429:
print()
print()
compare_and_report_length(*LIST)
compare_and_report_length(*LIST)
print()</lang>
print()
</lang>


{{out}}
{{out}}