先看看题目是什么
来学习
谢谢
def minmidmax(lis):
lis.sort()
n = len(lis)
result = []
result.append(lis)
result.append(lis)
temp = lis
while temp in lis:
temp += 1
else:
result.append(temp)
result.sort()
return result
lis1 = [-1, 4, 5, -23, 24]
result1 = minmidmax(lis1)
print(result1)
lis2 =
result2 = minmidmax(lis2)
print(result2)
lis3 =
result3 = minmidmax(lis3)
print(result3)
学习学习
回复
1
英语渣哭辽
a = [-12, 12, 43, 1, 2, 9]
b = [-45, -6733, -65,34, 554, 2342]
c = [-1, 4, 5, -23, 24]
d =
e =
# 逻辑实现函数
def fun(lst):
ma = max(lst)
mi = min(lst)
minx = min(filter(lambda x: x not in lst, range(mi + 1, ma)))
return
print(fun(a))
print(fun(b))
print(fun(c))
print(fun(d))
print(fun(e))
# -->>>
# [-12, -11, 43]
# [-6733, -6732, 2342]
# [-23, -22, 24]
# [-3, 0, 8]
# [-5, -3, 9]
本帖最后由 776667 于 2019-5-9 10:33 编辑
发重了
def fun72(x):
for i in range(min(x),max(x)):
if i not in x:
return
55555555555555555
import sys
def minMinmax(seq):
z = list(set().difference(set(seq[:])))
# 转集合求差集
if z != []:
return
else:
print("对不起,中间序列为原始序列的子序列")
return
while 1:
inp = input("请以英文逗号为分界输入系列数字(输入英文状态下的/以退出):")
if inp == "/":
sys.exit()
else:
try:
seq = list(eval(inp))
print(minMinmax(seq))
except TypeError:
print("不规范输入!请确保输入均为数字和英文字符")
还是得看一下中文版
def largest(array):
array.sort(reverse=True) #从大到小排序
return array #返回0号元素,最大值
def smallest(array):
array.sort() #从小到大排序
return array #返回0号元素,最小值
def minimumAbsent(array, smallest, largest):
minilist=list(range(smallest, largest))
lastlist=[]
for each in minilist:
if each not in array:
lastlist.append(each)
lastlist.sort() ##从小到大排序
return lastlist #返回0号元素,最小值
def minMinMax(array):
le = largest(array)
se = smallest(array)
mma = minimumAbsent(array, se, le)
newarray=[]
newarray.append(se)
newarray.append(mma)
newarray.append(le)
return newarray
本帖最后由 永恒的蓝色梦想 于 2019-8-20 11:46 编辑
看看中文
def minMinMax(x):
a=min(x);b=max(x)
for i in range(a+1,b):
if i not in x:return(a,i,b)
else:raise ValueError
def minMinMax(a:list):
min_num,max_num = a,a
for each in a:
if each <min_num:
min_num = each
elif max_num < each:
max_num = each
ms = min_num+1
for each in a:
if ms not in a:
break
else:
ms += 1
continue
return
print(minMinMax())
本帖最后由 lucky邪神 于 2019-9-24 02:56 编辑
def getnum(nums):
result=[]
result.append(min(nums))
new=min(nums)
while new in nums:
new+=1 #只考虑整数
result.append(new)
result.append(max(nums))
return result
我要看中文版
要看中文版