mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-08 12:35:59 +08:00
Pyupgrade to Python 3.9 (#4718)
* Pyupgrade to Python 3.9 * updating DIRECTORY.md Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
This commit is contained in:
@ -1,7 +1,8 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from bisect import bisect_left
|
||||
from functools import total_ordering
|
||||
from heapq import merge
|
||||
from typing import List
|
||||
|
||||
"""
|
||||
A pure Python implementation of the patience sort algorithm
|
||||
@ -44,7 +45,7 @@ def patience_sort(collection: list) -> list:
|
||||
>>> patience_sort([-3, -17, -48])
|
||||
[-48, -17, -3]
|
||||
"""
|
||||
stacks: List[Stack] = []
|
||||
stacks: list[Stack] = []
|
||||
# sort into stacks
|
||||
for element in collection:
|
||||
new_stacks = Stack([element])
|
||||
@ -55,7 +56,7 @@ def patience_sort(collection: list) -> list:
|
||||
stacks.append(new_stacks)
|
||||
|
||||
# use a heap-based merge to merge stack efficiently
|
||||
collection[:] = merge(*[reversed(stack) for stack in stacks])
|
||||
collection[:] = merge(*(reversed(stack) for stack in stacks))
|
||||
return collection
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user