Last active
December 7, 2015 09:44
-
-
Save m5wdev/391ad9aaf2533165e006 to your computer and use it in GitHub Desktop.
Pynton 3 mixed dict example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| Mixed dict type: | |
| """ | |
| blog_posts = {"Blog disclamer": "Here you can create anything text, integers, lists etc.", | |
| 1: {"post_title": "Title1", "post_content": "Content1"}, | |
| 2: {"post_title": "Title2", "post_content": "Content2"}, | |
| 3: {"post_title": "Title3", "post_content": "Content3"}, | |
| 4: {"post_title": "Title4", "post_content": "Content4"}} | |
| # let's print out our type just in case )) | |
| print( type(blog_posts) ) | |
| # output <class 'dict'> | |
| """ | |
| Profit: you may enter elements by they keys, instead using cycles like for, while etc. | |
| Resume: memory & time for execution economy | |
| """ | |
| print( blog_posts[2]["post_title"] ) | |
| # output "Title2" | |
| print( blog_posts[2]["post_content"] ) | |
| # output "Content2" | |
| print("post_title: {}, post_content: {}".format(blog_posts[2]["post_title"],blog_posts[2]["post_content"])) | |
| # output "post_title: Title2, post_content: Content2" | |
| print( blog_posts["Blog disclamer"] ) | |
| # output "Here you can create anything text, integers, lists etc." | |
| """ | |
| Try to be thrifty to memory and server resources and use cycles when they are really need | |
| """ | |
| i = 0 | |
| for blog_post in blog_posts: | |
| print( str(i) + ") " + str(blog_post) ) | |
| i = i+1 | |
| """ | |
| output | |
| 0) 1 | |
| 1) 2 | |
| 2) 3 | |
| 3) 4 | |
| 4) Blog disclamer | |
| """ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment