0

I was wondering while using the list.sort() function, leaving a question.

I tried to look at the library code, but couldn't figure out which file it was.

root@computer:/usr/lib/python3.7# ls
abc.py               compileall.py       filecmp.py      json             pathlib.py         reprlib.py        stringprep.py                               turtle.py
aifc.py              _compression.py     fileinput.py    keyword.py       pdb.py             re.py             string.py                                   types.py
antigravity.py       concurrent          fnmatch.py      lib2to3          __phello__.foo.py  rlcompleter.py    _strptime.py                                typing.py
argparse.py          configparser.py     formatter.py    lib-dynload      pickle.py          runpy.py          struct.py                                   unittest
ast.py               contextlib.py       fractions.py    LICENSE.txt      pickletools.py     sched.py          subprocess.py                               urllib
asynchat.py          contextvars.py      ftplib.py       linecache.py     pipes.py           secrets.py        sunau.py                                    uuid.py
asyncio              copy.py             functools.py    locale.py        pkgutil.py         selectors.py      symbol.py                                   uu.py
asyncore.py          copyreg.py          __future__.py   logging          platform.py        shelve.py         symtable.py                                 venv
base64.py            cProfile.py         genericpath.py  lzma.py          plistlib.py        shlex.py          _sysconfigdata_m_linux_x86_64-linux-gnu.py  warnings.py
bdb.py               crypt.py            getopt.py       macpath.py       poplib.py          shutil.py         sysconfig.py                                wave.py
binhex.py            csv.py              getpass.py      mailbox.py       posixpath.py       signal.py         tabnanny.py                                 weakref.py
bisect.py            ctypes              gettext.py      mailcap.py       pprint.py          _sitebuiltins.py  tarfile.py                                  _weakrefset.py
_bootlocale.py       curses              glob.py         _markupbase.py   profile.py         sitecustomize.py  telnetlib.py                                webbrowser.py
bz2.py               dataclasses.py      gzip.py         mimetypes.py     pstats.py          site.py           tempfile.py                                 wsgiref
calendar.py          datetime.py         hashlib.py      modulefinder.py  pty.py             smtpd.py          test                                        xdrlib.py
cgi.py               dbm                 heapq.py        multiprocessing  _py_abc.py         smtplib.py        textwrap.py                                 xml
cgitb.py             decimal.py          hmac.py         netrc.py         __pycache__        sndhdr.py         this.py                                     xmlrpc
chunk.py             difflib.py          html            nntplib.py       pyclbr.py          socket.py         _threading_local.py                         zipapp.py
cmd.py               dis.py              http            ntpath.py        py_compile.py      socketserver.py   threading.py                                zipfile.py
codecs.py            distutils           imaplib.py      nturl2path.py    _pydecimal.py      sqlite3           timeit.py
codeop.py            doctest.py          imghdr.py       numbers.py       pydoc_data         sre_compile.py    tokenize.py
code.py              dummy_threading.py  importlib       opcode.py        pydoc.py           sre_constants.py  token.py
collections          _dummy_thread.py    imp.py          operator.py      _pyio.py           sre_parse.py      traceback.py
_collections_abc.py  email               inspect.py      optparse.py      queue.py           ssl.py            tracemalloc.py
colorsys.py          encodings           io.py           os.py            quopri.py          statistics.py     trace.py
_compat_pickle.py    enum.py             ipaddress.py    _osx_support.py  random.py          stat.py           tty.py

selection, bubble, quick, insertion, shell ...

I would appreciate it if you let me know.

윤태일
  • 537
  • 1
  • 9
  • 21
  • Does this help? https://stackoverflow.com/questions/1517347/about-pythons-built-in-sort-method – alani Jul 30 '20 at 06:04
  • thanks!!! Then what file is in the code?? – 윤태일 Jul 30 '20 at 06:15
  • 1
    @윤태일 it's none of those files, those are standard library files written in Python, sorting is implemented in C as a part o the runtime (as are all the built-in objects, `list`, `dict`, `tuple`, `int`, `float`, etc). It is an adaptive mergesort called Timsort. The CPython source code is hosted in Github, [here](https://github.com/python/cpython/blob/ba18c0b13ba3c08077ea3db6658328523823a33f/Objects/listobject.c#L1051) is a link to where the implementation begins. – juanpa.arrivillaga Jul 30 '20 at 06:19
  • The inventor of Timsort is a StackOverflow user: https://stackoverflow.com/users/2705542/tim-peters – Selcuk Jul 30 '20 at 06:26

0 Answers0