k*****6 发帖数: 26 | 1 有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.
2. Make a function that takes in a multi-dimensional array/list and returns
the "diagonal" --- a list of the elements at the 1st row-and-1st column, 2nd
row-and-2nd column, 3rd row-and-3rd column, etc. That means if we have a
multi-dimensional array:
multiArray = [[3, -4, 12, 5], [5, 2, 11, -5], [2, 2, 0, 5], [-5, -3, 2, 2]
];
and we use the function call
diagonal(multiArray)
we get the output [3, 2, 0, 2] . | i***r 发帖数: 1035 | 2 第一个可以用dictionary,最后用value sort。
第二个用enumerate就可以做,或者map function | a****f 发帖数: 17 | 3 1 sum([1 for ele in numberList if ele == 5])
2 [ele[i] for i,ele in enumerate(inArray)]
【在 k*****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.
| a****e 发帖数: 9589 | 4 1, y = collections.Counter(x)
2,y = numpy.diag(x)
楼上的都没问题,取决于职位。如果应聘初级职位,一楼的方法足矣;中级level 的,
用二楼的;老人级别的,就得用叔的啦。
【在 k*****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.
| i****k 发帖数: 668 | 5 显然你挂了。。。因为英语没学好和人沟通存在问题。。。
【在 a****e 的大作中提到】 : 1, y = collections.Counter(x) : 2,y = numpy.diag(x) : 楼上的都没问题,取决于职位。如果应聘初级职位,一楼的方法足矣;中级level 的, : 用二楼的;老人级别的,就得用叔的啦。
| a****e 发帖数: 9589 | 6 还是你懂叔。
人之所以是人,就是因为会使用前人用过的工具和总结出的知识。
这个出题的人连这都不懂,偏要自己写。幼齿啊。
【在 i****k 的大作中提到】 : 显然你挂了。。。因为英语没学好和人沟通存在问题。。。
| j**********3 发帖数: 3211 | 7 人家不是特意说不能one line 么?楼上怎么都是一行的 |
|