{"id":1449,"date":"2017-08-03T21:22:29","date_gmt":"2017-08-03T21:22:29","guid":{"rendered":"http:\/\/ninecrows.com\/career\/?p=1449"},"modified":"2017-08-03T21:22:29","modified_gmt":"2017-08-03T21:22:29","slug":"a-little-bit-of-python","status":"publish","type":"post","link":"https:\/\/ninecrows.com\/career\/2017\/08\/03\/a-little-bit-of-python\/","title":{"rendered":"A Little bit of python&#8230;"},"content":{"rendered":"<p>Someone at work asked about shuffling cards in software (or similar type problems) so I write a small bit of python for them. Python isn&#8217;t a language that I&#8217;ve had much need for in the past but it was the language they are familiar with:<\/p>\n<pre>#! \/usr\/bin\/env python3\nimport random\n\n# Cards in each suit\ncards = ['Ace', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'Jack', 'Queen', 'King']\n\n# Suits of cards\nsuits = ['Clubs', 'Hearts', 'Diamonds', 'Spades']\n\n# Start with an empty deck and fill it with on card of each type in each suit\ndeck = []\nfor card in cards:\n for suit in suits:\n deck.append(card + \" of \" + suit)\n\n# Make sure we got the right number of cards in the deck\ndecksize = len(deck)\nprint (str(decksize) + \" cards in a deck\")\n\n# Shuffle the cards by walking through each location and swapping it with a\n# randomly chosen location in the deck.\nfor item in range(0, decksize):\n dest = random.randint(0, decksize - 1)\n # Swap by saving the contents of the destination spot, copying the source\n # spot there and then placing our saved card in the source location.\n temp = deck[dest]\n deck[dest] = deck[item]\n deck[item] = temp\n \nprint(deck);<\/pre>\n<p>Classic bit of swap based shuffle.<\/p>\n<p>I was a bit surprised to see that python has split into two largely incompatible languages with the transition from 2.x to 3.x being drawn out and there seems to be some question whether there will ever be a full transition.<\/p>\n<p>It does appear that with a bit of care it is possible to have both versions on one system with distinct names. Makes things workable if not exactly pleasant.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Someone at work asked about shuffling cards in software (or similar type problems) so I write a small bit of python for them. Python isn&#8217;t a language that I&#8217;ve had much need for in the past but it was the language they are familiar with: #! \/usr\/bin\/env python3 import random # Cards in each suit &hellip; <a href=\"https:\/\/ninecrows.com\/career\/2017\/08\/03\/a-little-bit-of-python\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">A Little bit of python&#8230;<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[9,2,22],"tags":[],"class_list":["post-1449","post","type-post","status-publish","format-standard","hentry","category-daily-blog","category-projects","category-sandbox"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p7F2Qc-nn","jetpack-related-posts":[],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/ninecrows.com\/career\/wp-json\/wp\/v2\/posts\/1449"}],"collection":[{"href":"https:\/\/ninecrows.com\/career\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ninecrows.com\/career\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ninecrows.com\/career\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ninecrows.com\/career\/wp-json\/wp\/v2\/comments?post=1449"}],"version-history":[{"count":1,"href":"https:\/\/ninecrows.com\/career\/wp-json\/wp\/v2\/posts\/1449\/revisions"}],"predecessor-version":[{"id":1450,"href":"https:\/\/ninecrows.com\/career\/wp-json\/wp\/v2\/posts\/1449\/revisions\/1450"}],"wp:attachment":[{"href":"https:\/\/ninecrows.com\/career\/wp-json\/wp\/v2\/media?parent=1449"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ninecrows.com\/career\/wp-json\/wp\/v2\/categories?post=1449"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ninecrows.com\/career\/wp-json\/wp\/v2\/tags?post=1449"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}