How to create a dictionary with a number as key and its cube as value in Python

1 Answer

0 votes
def cube(x):
	x = x ** 3
	return x

dict = {x: cube(x) for x in (6, 7, 8, 9, 10)} 

print(dict)

print(type(dict))




'''
run:

{6: 216, 7: 343, 8: 512, 9: 729, 10: 1000}
<class 'dict'>

'''

 



answered Jan 12, 2021 by avibootz

Related questions

1 answer 67 views
4 answers 200 views
1 answer 113 views
2 answers 139 views
...