Advertisement
spliter93

Untitled

Jul 18th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. def binomial_coefficients(n):
  2.  
  3. 'Coefficients of (x + 1) ** n'
  4.  
  5. return [(c := c * (n - k + 1) // k if k else 1) for k in range(n+1)]
  6.  
  7.  
  8.  
  9. >>> for n in range(10):
  10.  
  11. print(binomial_coefficients(n))
  12.  
  13.  
  14.  
  15. [1]
  16.  
  17. [1, 1]
  18.  
  19. [1, 2, 1]
  20.  
  21. [1, 3, 3, 1]
  22.  
  23. [1, 4, 6, 4, 1]
  24.  
  25. [1, 5, 10, 10, 5, 1]
  26.  
  27. [1, 6, 15, 20, 15, 6, 1]
  28.  
  29. [1, 7, 21, 35, 35, 21, 7, 1]
  30.  
  31. [1, 8, 28, 56, 70, 56, 28, 8, 1]
  32.  
  33. [1, 9, 36, 84, 126, 126, 84, 36, 9, 1]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement