由买买提看人间百态

topics

全部话题 - 话题: numberlist
(共0页)
t****u
发帖数: 709
1
来自主题: DataSciences版 - 求助:关于2个python的题目
numberList=[5, 12, 0, 7, 2, 5, 10, 9, 12, 5]
def numRepeats(numberList, number):
return map(str, numberList).count(str(number))
print numRepeats(numberList, 5)
第一个一行就足够了
def diagonal(multiArray):
nrow = len(multiArray)
diagonalList = []
for i in xrange(nrow):
diagonalList.append(multiArray[i][i])
return diagonalList
print diagonal(multiArray)
对空 multiArray 也一样 没问题.
k*****6
发帖数: 26
2
有python比较熟练的朋友帮忙看下这两道题吗?万分感激。。
Do both of these problems using at least one loop each and not using any
special pre-existing functions that give you the answer with just one line
of code.
1. Make a function to count the number of times a specified number is
repeated in a list/array. That means that if we have a number list
numberList=[5, 12, 0, 7, 2, 5, 10, 9, 12, 5];
and we use the function call
numRepeats(numberList, 5)
we get the output: 3 --- meaning 5 occurs three times in numberList.... 阅读全帖
k*****6
发帖数: 26
3
来自主题: Programming版 - 求助:关于2个python的题目
有python比较熟练的朋友帮忙看下这两道题吗?万分感激。。
Do both of these problems using at least one loop each and not using any
special pre-existing functions that give you the answer with just one line
of code.
1. Make a function to count the number of times a specified number is
repeated in a list/array. That means that if we have a number list
numberList=[5, 12, 0, 7, 2, 5, 10, 9, 12, 5];
and we use the function call
numRepeats(numberList, 5)
we get the output: 3 --- meaning 5 occurs three times in numberList.... 阅读全帖
k*****6
发帖数: 26
4
来自主题: Computation版 - 求助:麻烦看看关于2个python的题目
有python比较熟练的朋友帮忙看下这两道题吗?万分感激。。
Do both of these problems using at least one loop each and not using any
special pre-existing functions that give you the answer with just one line
of code.
1. Make a function to count the number of times a specified number is
repeated in a list/array. That means that if we have a number list
numberList=[5, 12, 0, 7, 2, 5, 10, 9, 12, 5];
and we use the function call
numRepeats(numberList, 5)
we get the output: 3 --- meaning 5 occurs three times in numberList.... 阅读全帖
k*****6
发帖数: 26
5
来自主题: DataSciences版 - 求助:关于2个python的题目
有python比较熟练的朋友帮忙看下这两道题吗?万分感激。。
Do both of these problems using at least one loop each and not using any
special pre-existing functions that give you the answer with just one line
of code.
1. Make a function to count the number of times a specified number is
repeated in a list/array. That means that if we have a number list
numberList=[5, 12, 0, 7, 2, 5, 10, 9, 12, 5];
and we use the function call
numRepeats(numberList, 5)
we get the output: 3 --- meaning 5 occurs three times in numberList.... 阅读全帖
a****f
发帖数: 17
6
来自主题: Programming版 - 求助:关于2个python的题目
1 sum([1 for ele in numberList if ele == 5])
2 [ele[i] for i,ele in enumerate(inArray)]
(共0页)