免费提示词
写带类型注解和测试的 Python 算法
适合做数据处理的同学。你要提供:要解决的数据或优化问题。
请为我解决的数据处理/优化问题编写一段结构清晰、带完整类型注解(Type Hints)、复杂度分析与 3 组边界测试用例的 Python 代码。
示例片段(ans-py-algorithms.py)
只是写法示意,不是完整程序。
# ANS Dijkstra 最短路径纯 Python 优先队列标准实现 (ans-py-algorithms.py)
import heapq
def ans_shortest_path(graph: dict, start: str) -> dict:
dist = {node: float("inf") for node in graph}
dist[start] = 0
pq = [(0, start)]
while pq:
d, u = heapq.heappop(pq)
if d > dist[u]: continue
for v, w in graph[u].items():
if d + w < dist[v]: dist[v] = d + w; heapq.heappush(pq, (dist[v], v))
return dist免费使用,可用于个人和商业项目。模型输出的内容由你自己核对。