gpt4 book ai didi

python 列表未定义错误不知道如何定义列表

转载 作者:行者123 更新时间:2023-12-01 00:40:27 25 4
gpt4 key购买 nike

def findMedianSortedArrays(self, nums1: List[int], nums2: List[int]) -> float:

concat = sorted(nums1 + nums2)
median = concat[len(concat) //2] if len(concat)%2 ==0 else (concat[len(concat) //2] +concat[(len(concat)+1)//2])/2
return median

错误代码如下

<小时/>

NameError Traceback (most recent call last) in ----> 1 def findMedianSortedArrays(self, nums1: List[int], nums2: List[int]) -> float: 2 3 concat = sorted(nums1 + nums2) 4 median = concat[len(concat) //2] if len(concat)%2 ==0 else (concat[len(concat) //2]
+concat[(len(concat)+1)//2])/2 5 return median

NameError: name 'List' is not defined

最佳答案

只需添加导入来自键入导入列表

关于python 列表未定义错误不知道如何定义列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57385776/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com