Skip to content

Instantly share code, notes, and snippets.

View 1o55's full-sized avatar
💭
🤪

Adam Parichy 1o55

💭
🤪
View GitHub Profile

aspe:keyoxide.org:HOT6KMK2MDVWOHG5LNT3XFRK5U

Keybase proof

I hereby claim:

  • I am 1o55 on github.
  • I am 1055 (https://keybase.io/1055) on keybase.
  • I have a public key ASCDzIHJ4BtrejU2kntCjFFQkMLx_3yumVGI5prmJ9RSCgo

To claim this, I am signing this object:

@1o55
1o55 / comprehensions.md
Created August 8, 2018 14:36 — forked from bearfrieze/comprehensions.md
Comprehensions in Python the Jedi way

Comprehensions in Python the Jedi way

by Bjørn Friese

Beautiful is better than ugly. Explicit is better than implicit.

-- The Zen of Python

I frequently deal with collections of things in the programs I write. Collections of droids, jedis, planets, lightsabers, starfighters, etc. When programming in Python, these collections of things are usually represented as lists, sets and dictionaries. Oftentimes, what I want to do with collections is to transform them in various ways. Comprehensions is a powerful syntax for doing just that. I use them extensively, and it's one of the things that keep me coming back to Python. Let me show you a few examples of the incredible usefulness of comprehensions.

on("chat:message", function(msg) {
//checks if the message is 1) an API message and 2) contains our call
if (msg.type == "api" && msg.content.indexOf("!wildshape") !== -1) {
//splits the contents of the message in to parts and stores them in an array
var args = msg.content.split(/\s+/);
//deletes the "!wildshape" from the array of message contents
args.shift();
var mycharName = args[0];
var mycharobj = findObjs({
_type: "character",