This file contains 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
<p> | |
My programming language of preference is python for the simple reason that I feel I write better code faster with it then I do with other languages. However also has a lot of nice tricks and idioms to do things well. And partly as a reminder to myself to use them, and partly because I thought this might be of general interest I have put together this collection of some of my favourite idioms. I am also putting this on <a href="https://gist.github.com/codefisher/9d7993ddbf404c505128">gist.github.com</a> so that anyone that wants to contribute there own things can, and I will try and keep this post up to date. | |
</p> | |
<h2>enumerate</h2> | |
<p> | |
A fairly common thing to do is loop over a list while also keeping track of what index we are up to. Now we could use a <code>count</code> variable, but python gives us a nicer syntax for this with the <code>enumerate()</code> function. | |
<script src="https://gist.github.com/codefisher/9d7993ddbf404c505128.js?file=enumerate.py"></script> |
This file contains 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
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
import web, json, time, mpd, collections | |
STATIONS = { | |
"FoxNews" : "mmsh://209.107.209.181:80/D/138/13873/v0001/reflector:24137?MSWMExt=.asf", | |
"Classic" : "http://radio02-cn03.akadostream.ru:8100/classic128.mp3", | |
"Jazz": "http://streaming208.radionomy.com:80/A-JAZZ-FM-WEB" | |
} |