MCPcopy Create free account
hub / github.com/ipython/ipython / sort

Method sort

IPython/utils/text.py:203–230  ·  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)

(self,field= None,  nums = False)

Source from the content-addressed store, hash-verified

201 return res
202
203 def sort(self,field= None, nums = False):
204 """ sort by specified fields (see fields())
205
206 Example::
207
208 a.sort(1, nums = True)
209
210 Sorts a by second field, in numerical order (so that 21 > 3)
211
212 """
213
214 #decorate, sort, undecorate
215 if field is not None:
216 dsu = [[SList([line]).fields(field), line] for line in self]
217 else:
218 dsu = [[line, line] for line in self]
219 if nums:
220 for i in range(len(dsu)):
221 numstr = "".join([ch for ch in dsu[i][0] if ch.isdigit()])
222 try:
223 n = int(numstr)
224 except ValueError:
225 n = 0
226 dsu[i][0] = n
227
228
229 dsu.sort()
230 return SList([t[1] for t in dsu])
231
232
233# FIXME: We need to reimplement type specific displayhook and then add this

Callers 15

test_SListFunction · 0.95
test_caseMethod · 0.80
test_case_showallMethod · 0.80
test_nocaseMethod · 0.80
test_nocase_showallMethod · 0.80
test_dict_attributesMethod · 0.80
findsourceFunction · 0.80
addMethod · 0.80
sort_transformersMethod · 0.80
sort_checkersMethod · 0.80
logstartMethod · 0.80
who_lsMethod · 0.80

Calls 2

SListClass · 0.85
fieldsMethod · 0.80

Tested by 12

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
reportFunction · 0.64
loadTestsFromModuleMethod · 0.64