Guest User

Untitled

a guest
Nov 18th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. void printRepeating(int arr[], int size)
  2. {
  3. int *count = (int *)calloc(sizeof(int), (size - 2));
  4. int i;
  5.  
  6. printf(" Repeating elements are ");
  7. for(i = 0; i < size; i++)
  8. {
  9. if(count[arr[i]] == 1)
  10. printf(" %d ", arr[i]);
  11. else
  12. count[arr[i]]++;
  13. }
  14. }
  15.  
  16. a=[1,2,3,2,4,3,1,7,4,3];
  17. b=[];
  18. for i in a:
  19. b[i]=b[i]+1;
  20.  
  21. IndexError: list index out of range
  22.  
  23. a = [1,2,3,2,4,3,1,7,4,3]
  24. b = {}
  25. for i in a:
  26. # get(key, default) falls back to default if key is not present
  27. b[i] = b.get(i, 0) + 1
  28.  
  29. > b
  30. {1: 2, 2: 2, 3: 3, 4: 2, 7: 1}
  31. > b[3]
  32. 3
  33.  
  34. a = [1,2,3,2,4,3,1,7,4,3]
  35. print("Repeating elements are")
  36. for i in a:
  37. if a.count(i) > 1:
  38. print(i)
  39.  
  40. from collections import Counter
  41. a = [1,2,3,2,4,3,1,7,4,3]
  42. counter = Counter(a)
  43. print(a.most_common())
  44.  
  45. a=[1,2,3,2,4,3,1,7,4,3]
  46. b={}
  47. for i in a:
  48. if i in b:
  49. b[i]+=1
  50. else:
  51. b[i]=1
Add Comment
Please, Sign In to add comment