Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,845 questions

51,766 answers

573 users

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 74 views
4 answers 216 views
1 answer 125 views
2 answers 148 views
...