Last active
December 15, 2015 18:19
-
-
Save philsturgeon/5302549 to your computer and use it in GitHub Desktop.
Generating a 'X','Y' string from an array for an IN query with as little code as possible in Python and PHP. This is done as a learning exercise for me to see how list comprehensions work, being used for some random Twitter "your friends signed up" worker.
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
<?php | |
$users = [['id' => 1, 'name' => 'Jack'], ['id' => 2, 'name' => 'Jill']]; | |
echo implode(',', array_map(function($u) { return "'{$u['id']}'"; }, $users)); |
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
users = [{'id': 1, 'name': 'Jack'}, {'id': 2, 'name': 'Jill'}]; | |
print ','.join(["'{0}'".format(u['id']) for u in users]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment