Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
- a = [1,2,3,2,4,3,1,7,4,3]
- b = {}
- for i in a:
- # get(key, default) falls back to default if key is not present
- b[i] = b.get(i, 0) + 1
- > b
- {1: 2, 2: 2, 3: 3, 4: 2, 7: 1}
- > b[3]
- 3
- a = [1,2,3,2,4,3,1,7,4,3]
- print("Repeating elements are")
- for i in a:
- if a.count(i) > 1:
- print(i)
- from collections import Counter
- a = [1,2,3,2,4,3,1,7,4,3]
- counter = Counter(a)
- print(a.most_common())
- a=[1,2,3,2,4,3,1,7,4,3]
- b={}
- for i in a:
- if i in b:
- b[i]+=1
- else:
- b[i]=1
Add Comment
Please, Sign In to add comment