Advertisement
Guest User

Untitled

a guest
Apr 25th, 2015
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. def main():
  2.  
  3. #input some numbers and make a list out of them
  4. a = input('Enter numbers:')
  5. a = a.split()
  6. alist = list(a)
  7. new_numbers = []
  8. for n in alist:
  9. new_numbers.append(int(n))
  10. alist = new_numbers
  11.  
  12. #Create a dictionary to count the number of instances each number occurs
  13. newlist = {}
  14.  
  15. for i in alist:
  16. if i in newlist:
  17. newlist[i]+=1
  18. else:
  19. newlist[i] = 1
  20. #list2 contains the values that were actually inputted
  21. list2 = list(newlist.keys())
  22. #list3 has how many times that value occurs
  23. list3 = list(newlist.values())
  24.  
  25. #this for loop prints out how many times each number from the output occurred
  26. for x in range(len(list2)):
  27. if list3[x] > 1:
  28. print(list2[x],'occurs',list3[x],'times')
  29. if list3[x] == 1:
  30. print(list2[x],'occurs',list3[x],'time')
  31.  
  32.  
  33. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement