Advertisement
here2share

# module_timeit_on_list_count_vs_dict.py

Sep 16th, 2015
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.82 KB | None | 0 0
  1. # module_timeit_on_list_count_vs_dict.py
  2. import timeit
  3.  
  4. print timeit.timeit('len(set(s))<=1', 's=[1]*5000', number=10000)
  5. print timeit.timeit('len(set(s))<=1', 's=[1]*4999+[2]', number=10000)
  6. print timeit.timeit('s.count(s[0])==len(s)', 's=[1]*5000', number=10000)
  7. print timeit.timeit('s.count(s[0])==len(s)', 's=[1]*4999+[2]', number=10000)
  8.  
  9. s=[1]*5
  10. print s, s.count(s[0])==len(s)
  11. s=[1]*4+[2]
  12. print s, s.count(s[0])==len(s)
  13.  
  14. s=[1]*5
  15. print s, len(set(s))<=1
  16. s=[1]*4+[2]
  17. print s, len(set(s))<=1
  18.  
  19. s=[(1,0)]*5
  20. print s, len(set(s))<=1
  21. s=[(1,0)]*4+[(1,2)]
  22. print s, len(set(s))<=1
  23.  
  24. s=[[1,0]]*5
  25. print s, len(set(map(str,s)))<=1
  26. s=[[1,0]]*4+[[1,2]]
  27. print s, len(set(map(str,s)))<=1
  28.  
  29. # !!! Needs to be a immutable unlike the count method
  30. s=[[1,0]]*5
  31. print s, len(set(s))<=1
  32. s=[[1,0]]*4+[[1,2]]
  33. print s, len(set(s))<=1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement