|
29 | 29 | from sage.categories.sets_cat import EmptySetError |
30 | 30 |
|
31 | 31 |
|
32 | | -def repr_list(items, left=4, right=2): |
| 32 | +def _repr_items(items, left=4, right=2): |
| 33 | + r""" |
| 34 | + Return a string representation of the items in ``items`` |
| 35 | + with possible ellipsis. |
| 36 | +
|
| 37 | + INPUT: |
| 38 | +
|
| 39 | + - ``items`` -- a list |
| 40 | +
|
| 41 | + - ``left`` -- an integer (default: ``4``), the maximum |
| 42 | + number of items listed at the beginning |
| 43 | +
|
| 44 | + - ``right`` -- an integer (default: ``2``), the maximum |
| 45 | + number of items listed at the end |
| 46 | +
|
| 47 | + EXAMPLES:: |
| 48 | +
|
| 49 | + sage: from sage.sets.primes import _repr_items |
| 50 | + sage: _repr_items(range(5)) |
| 51 | + '0, 1, 2, 3, 4' |
| 52 | + sage: _repr_items(range(10)) |
| 53 | + '0, 1, 2, 3, ..., 8, 9' |
| 54 | + sage: _repr_items(range(10), left=3, right=3) |
| 55 | + '0, 1, 2, ..., 7, 8, 9' |
| 56 | + """ |
33 | 57 | if len(items) <= left + right + 1: |
34 | 58 | s = [str(item) for item in items] |
35 | 59 | else: |
@@ -367,18 +391,18 @@ def _repr_(self): |
367 | 391 | if not included: |
368 | 392 | return "Empty set of prime numbers" |
369 | 393 | else: |
370 | | - return "Finite set of prime numbers: %s" % repr_list(included) |
| 394 | + return "Finite set of prime numbers: %s" % _repr_items(included) |
371 | 395 | if self._modulus == 1: |
372 | 396 | s = "Set of all prime numbers" |
373 | 397 | else: |
374 | | - s = "Set of prime numbers congruent to %s modulo %s" % (repr_list(classes), self._modulus) |
| 398 | + s = "Set of prime numbers congruent to %s modulo %s" % (_repr_items(classes), self._modulus) |
375 | 399 | if included: |
376 | | - s += " with %s included" % repr_list(included) |
| 400 | + s += " with %s included" % _repr_items(included) |
377 | 401 | if excluded: |
378 | 402 | if not included: |
379 | | - s += " with %s excluded" % repr_list(excluded) |
| 403 | + s += " with %s excluded" % _repr_items(excluded) |
380 | 404 | else: |
381 | | - s += " and %s excluded" % repr_list(excluded) |
| 405 | + s += " and %s excluded" % _repr_items(excluded) |
382 | 406 | s += ": %s, ..." % (", ".join([str(n) for n in self[:4]])) |
383 | 407 | return s |
384 | 408 |
|
|
0 commit comments