MCPcopy Index your code
hub / github.com/ipython/ipython / sort

Method sort

IPython/utils/text.py:224–255  ·  view source on GitHub ↗

sort by specified fields (see fields()) Example:: a.sort(1, nums = True) Sorts a by second field, in numerical order (so that 21 > 3)

(  # type:ignore[override]
        self,
        field: Optional[List[str]] = None,
        nums: bool = False,
    )

Source from the content-addressed store, hash-verified

222 return res
223
224 def sort( # type:ignore[override]
225 self,
226 field: Optional[List[str]] = None,
227 nums: bool = False,
228 ) -> Self:
229 """sort by specified fields (see fields())
230
231 Example::
232
233 a.sort(1, nums = True)
234
235 Sorts a by second field, in numerical order (so that 21 > 3)
236
237 """
238
239 #decorate, sort, undecorate
240 if field is not None:
241 dsu = [[SList([line]).fields(field), line] for line in self]
242 else:
243 dsu = [[line, line] for line in self]
244 if nums:
245 for i in range(len(dsu)):
246 numstr = "".join([ch for ch in dsu[i][0] if ch.isdigit()])
247 try:
248 n = int(numstr)
249 except ValueError:
250 n = 0
251 dsu[i][0] = n
252
253
254 dsu.sort()
255 return type(self)([t[1] for t in dsu])
256
257
258def indent(instr: str, nspaces: int = 4, ntabs: int = 0, flatten: bool = False) -> str:

Callers 15

test_SListFunction · 0.95
addMethod · 0.80
sort_transformersMethod · 0.80
sort_checkersMethod · 0.80
logstartMethod · 0.80
who_lsMethod · 0.80
_format_pathMethod · 0.80
__repr__Method · 0.80
storeMethod · 0.80
hdictMethod · 0.80
test_caseMethod · 0.80
test_case_showallMethod · 0.80

Calls 2

SListClass · 0.85
fieldsMethod · 0.80

Tested by 10

test_SListFunction · 0.76
test_caseMethod · 0.64
test_case_showallMethod · 0.64
test_nocaseMethod · 0.64
test_nocase_showallMethod · 0.64
test_dict_attributesMethod · 0.64