我看过this和this。我想知道是否可以在不使用集合等库的情况下做到这一点,而是使用简单的循环结构。 我可以在Python中做到这一点吗?在Python中查找数组中整数出现的次数
void printRepeating(int arr[], int size)
{
int *count = (int *)calloc(sizeof(int), (size - 2));
int i;
printf(" Repeating elements are ");
for(i = 0; i < size; i++)
{
if(count[arr[i]] == 1)
printf(" %d ", arr[i]);
else
count[arr[i]]++;
}
}
我试着这样做 -
a=[1,2,3,2,4,3,1,7,4,3];
b=[];
for i in a:
b[i]=b[i]+1;
,但我得到
IndexError: list index out of range
是否有办法解决它?
它不起作用,因为您的列表'B'是空 – Chr
可能的复制[Python的:计算列表重复的元素(http://stackoverflow.com/questions/23240969/python-count-重复列表中的元素) –
在其他链接中接受的答案可以不使用库。 –