# -*- coding: utf-8 -*- # 请使用迭代查找一个list中最小和最大值,并返回一个tuple from collections import Iterable def findMinAndMax(L): if len(L) == 0: return (None,None) if isinstance(L,Iterable) == True: min = L[0] max = L[0] for x in L: if x > max: max = x if x < min:
# -*- coding: utf-8 -*- #使用迭代查找一个list中最小和最大值,并返回一个tuple #遍历list,找到最小值 def findMinAndMax(L): if L==[]: return(None, None) else: a=L[0] b=L[0] for num in L: if num<a: a=num for num in L: if num>b: b=num return (a,b) print(findMinAndMax([1,2,3,4,5,6]))
请使用迭代查找一个list中最小和最大值,并返回一个tuple: 要注意返回的值的类型是不是tuple def findMinAndMax(L): min=0 max=0 if len(L)==0: return tuple([None,None]) else: for i in L: for j in L: if i>=j: i=j min=i #找出最小值 for i in L: for j in L: if i<=j: i=j max=i #找出最大值 return tuple([min
/****************************************************************** find the biggest x number in a sequence* the basic method is the same as the QuickSort** 1. move the smaller one before the pivot* 2. move the bigger one after the pivot* 3. determin
如何快速查找一个字符串中出现最多的字符,并统计出现的次数? 可以使用hash数组,也就是关联数组实现快速查找功能. function seek(str) { var hash = []; var max=-1; var max_key=''; for(var i=0,l=str.length;i<l;i++){ var key=str[i]; if(!hash[key]){ hash[key]=1; }else{ hash[key]++; } } //console.dir(hash); //遍