# Python | sympy.as_coefficients_dict() method

With the help of `sympy.as_coefficients_dict()` method, we are able to find the coefficients of all the elements in the dictionary that exist in the mathematical expression by using `sympy.as_coefficients_dict()` method.

Syntax : `sympy.as_coefficients_dict()`
Return : Return the coefficients of mathematical expression in the dictionary.

Example #1 :
In this example we can see that by using `sympy.as_coefficients_dict()` method, we can find all the coefficients in a mathematical expression and return a dictionary of it.

 `# import sympy ` `from` `sympy ``import` `*`  ` `  `x ``=` `symbols(``'x'``) ` ` `  `# Use sympy.as_coefficients_dict() method ` `gfg ``=` `x``*``*``3` `+` `21` `*` `x ``+` `12` ` `  `print``(gfg.as_coefficients_dict()) `

Output :

defaultdict(, {1: 12, x**3: 1, x: 21})

Example #2 :

 `# import sympy ` `from` `sympy ``import` `*`  ` `  `x ``=` `symbols(``'x'``) ` ` `  `# Use sympy.as_coefficients_dict() method ` `gfg ``=` `x``*``*``3` `+` `21` `*` `x``*``*``2` `+` `121` `*` `x ``+` `4` ` `  `print``(gfg.as_coefficients_dict()) `

Output :

defaultdict(, {1: 4, x**3: 1, x**2: 21, x: 121})

My Personal Notes arrow_drop_up Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.