mirror of
https://github.com/not-kennethreitz/convore.json.git
synced 2026-06-05 23:20:19 +00:00
1 line
3.0 KiB
JSON
1 line
3.0 KiB
JSON
[{"user_id": 11592, "stars": [{"date_created": 1301472837.7530241, "user_id": 1}, {"date_created": 1301473174.014704, "user_id": 10074}, {"date_created": 1301486911.362571, "user_id": 5778}], "topic_id": 16190, "date_created": 1301472702.1692729, "message": "def regroup(l, n):\n \"\"\" Regroup iterable l by series of n elements\n \n >>> list(regroup([1,2,3,4,5,6,'EVIL_VALUE'], 3))\n [[1, 2, 3], [4, 5, 6], ['EVIL_VALUE']]\n \"\"\"\n for i in xrange(0,len(l), n): yield l[i:i+n]", "group_id": 292, "id": 479540}, {"user_id": 10074, "stars": [], "topic_id": 16190, "date_created": 1301472284.123632, "message": "Hey guys,\nI want to divide a string in pairs of maximum 2 characters.\nprint map(lambda x,y: x+y, 'abcdefgh'[0::2],'abcdefgh'[1::2])\nthis works fine for an even number of characters. But It should work for an odd number too.\nI tried this: map(lambda x='_',y='_': x+y, 'abcdefgh'[0::2],'abcdefgh'[1::2]) to set a default value if something is not set, but this doesn't work. Any suggestions?", "group_id": 292, "id": 479518}, {"user_id": 10074, "stars": [{"date_created": 1301486892.048543, "user_id": 5778}], "topic_id": 16190, "date_created": 1301472914.027566, "message": "Found another solution:\nmap(lambda x,y: (x if x!=None else '_')+(y if y!=None else '_'), 'abcdefgh'[0::2],'abcdefgh'[1::2])", "group_id": 292, "id": 479587}, {"user_id": 10074, "stars": [], "topic_id": 16190, "date_created": 1301473225.650924, "message": "Is my solution consistent? I mean, is it ok? Or do you think its a bad style?", "group_id": 292, "id": 479619}, {"user_id": 11592, "stars": [{"date_created": 1301487002.5848391, "user_id": 5778}], "topic_id": 16190, "date_created": 1301473541.1663289, "message": "1) map sticks whole list in memory so it would have memory issues on large data. 2) Lambdas are unnecessary most of the time, so if you typing it do a quick check: maybe you should use list comp's or gen expressions. 3) Gluing strings with a \u00ab+\u00bb takes a lot of operations juggling with objects, so it's slow. 4) For each element you do unnecessary ternary expression... twice! 5) And that's only for 2-element groups.", "group_id": 292, "id": 479643}, {"user_id": 3978, "stars": [], "topic_id": 16190, "date_created": 1301494786.5076821, "message": "Note this will force the iterable into a list which will load it all into memory.", "group_id": 292, "id": 481844}, {"user_id": 3978, "stars": [], "topic_id": 16190, "date_created": 1301494652.339236, "message": "import math\n\ndef section(iterable, by):\n \"\"\"\n >>> section([1, 2, 3, 4, 5], 2)\n <<< [[1, 2], [3, 4], [5]]\n \"\"\"\n iterable = list(iterable)\n x = int(math.ceil(float(len(iterable)) / float(by)))\n return [iterable[by * i:by * (i + 1)] for i in xrange(x)]\n", "group_id": 292, "id": 481840}, {"user_id": 2588, "stars": [], "topic_id": 16190, "date_created": 1301505260.1286769, "message": "some suggestions: http://stackoverflow.com/questions/312443/how-do-you-split-a-list-into-evenly-sized-chunks-in-python", "group_id": 292, "id": 483185}] |