t****u 发帖数: 709 | 1 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 也一样 没问题. |
|
g****u 发帖数: 25 | 2 童鞋,你编程实在有点弱啊。。。
def numRepeats(numlist, num):
count = 0
for i in numlist:
if i == num: count += 1
return count
def diagonal(multiArray):
m = len(multiArray)
if m == 0: return []
n = len(multiArray[0])
diag = []
for i in range(min(m,n)):
diag.append(multiArray[i][i])
return diag |
|
k*****6 发帖数: 26 | 3 有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 有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 有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 | 6 有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.... 阅读全帖 |
|
B*****g 发帖数: 34098 | 7 啥也不说了,你直接发包子吧
1
def numRepeats(numlist, num):
return numlist.count(num)
or
def numRepeats(numlist, num):
return sum(1 for s in numlist if s==num)
2
def diagonal(multiArray):
return [s[idx] for idx,s in enumerate(multiArray)] |
|
|
r*********r 发帖数: 3195 | 9 does anyone use it seriously? is it flexible ( can it be interfaced with
existing libs like GSL)?
any opinion is welcomed. |
|
c*****z 发帖数: 182 | 10 i don't know the answer, but i want to ask a related questions:
anyone use the uBlas seriously?
better than gsl?
i saw it didn't even have svd decomposer |
|
r*********r 发帖数: 3195 | 11 blas only contains low level operations, SVD shouldn't be in there. |
|
|