mirror of
https://github.com/not-kennethreitz/convore.json.git
synced 2026-06-05 23:20:19 +00:00
1 line
7.0 KiB
JSON
1 line
7.0 KiB
JSON
[{"user_id": 1736, "stars": [], "topic_id": 14424, "date_created": 1300815664.147398, "message": "Better question, {'foo': 0} or dict(foo=0) :-)", "group_id": 292, "id": 409396}, {"user_id": 3946, "stars": [{"date_created": 1300882221.117995, "user_id": 4937}, {"date_created": 1300987779.3036909, "user_id": 8391}], "topic_id": 14424, "date_created": 1300817672.001586, "message": "plain {a: b} for new dicts, dict(old, update=a, update=b) when I want .update() as an expression.", "group_id": 292, "id": 409781}, {"user_id": 7, "stars": [{"date_created": 1300918504.9695261, "user_id": 141}, {"date_created": 1301008116.9989691, "user_id": 20326}, {"date_created": 1301171212.975244, "user_id": 14874}, {"date_created": 1302167271.6969581, "user_id": 5069}], "topic_id": 14424, "date_created": 1300827717.5491221, "message": "{}", "group_id": 292, "id": 411767}, {"user_id": 7, "stars": [{"date_created": 1300848916.913718, "user_id": 1243}, {"date_created": 1300886474.772464, "user_id": 7385}], "topic_id": 14424, "date_created": 1300827727.150862, "message": "the only time I use dict() is to convert a list of 2-tuples", "group_id": 292, "id": 411769}, {"user_id": 291, "stars": [], "topic_id": 14424, "date_created": 1300828038.7976899, "message": "I don't really have a preference, either is fine w/ me. Using \"dict()\" is nice when you're defining literals w/ string or byte keys b/c you have to type fewer quotes...", "group_id": 292, "id": 411818}, {"user_id": 3354, "stars": [{"date_created": 1300987845.3916121, "user_id": 8391}], "topic_id": 14424, "date_created": 1300832165.430831, "message": "I' m all for easier typing, though. And really encouraged that nobody has brought timeit into the thread yet :)", "group_id": 292, "id": 412339}, {"user_id": 3354, "stars": [{"date_created": 1300881670.0982239, "user_id": 22985}, {"date_created": 1300987829.010258, "user_id": 8391}], "topic_id": 14424, "date_created": 1300832046.149451, "message": "@coderanger Observe that your second alternative can only produce a subset of the dicts that a literal can - i.e. those with Python identifiers as keys. dict(1='One') is a syntax error.", "group_id": 292, "id": 412325}, {"user_id": 18539, "stars": [], "topic_id": 14424, "date_created": 1300840910.4671359, "message": "dict(old, update=a, update=b) doesn't look like it could work", "group_id": 292, "id": 413092}, {"user_id": 18539, "stars": [{"date_created": 1300889581.1860731, "user_id": 21122}], "topic_id": 14424, "date_created": 1300840945.978791, "message": "To answer the actual question: dict if I'm building something from existing data structures, dict literals for new dicts, exceptions for cleanliness apply", "group_id": 292, "id": 413101}, {"user_id": 3354, "stars": [], "topic_id": 14424, "date_created": 1300851569.350466, "message": "@lvh Yes, that would give a syntax error in most Pythons.", "group_id": 292, "id": 413875}, {"user_id": 18985, "stars": [], "topic_id": 14424, "date_created": 1300851595.529541, "message": "@sshirokov hmm interesting trick, wonder why that's not in the docs", "group_id": 292, "id": 413883}, {"user_id": 19652, "stars": [{"date_created": 1300918479.266957, "user_id": 141}], "topic_id": 14424, "date_created": 1300904597.713522, "message": "I think it depends on the code. for empty I just use {} for initializing sometimes it's better do use dict() as it looks cleaner.", "group_id": 292, "id": 419464}, {"user_id": 24439, "stars": [{"date_created": 1301008144.274168, "user_id": 20326}, {"date_created": 1301082668.738946, "user_id": 19652}], "topic_id": 14424, "date_created": 1300980204.465636, "message": "Meh, premature optimization and all that", "group_id": 292, "id": 427713}, {"user_id": 24439, "stars": [], "topic_id": 14424, "date_created": 1300980043.4723179, "message": "I usually use dictionary displays (ie. {...}) but I sometimes use the dict() form when it reads better; for example, when working with a dict that's going to be used with **kwargs, or perhaps HTTP form data.", "group_id": 292, "id": 427689}, {"user_id": 5773, "stars": [{"date_created": 1301190257.5028579, "user_id": 24931}], "topic_id": 14424, "date_created": 1300980119.565522, "message": "This will only be an issue if your code gets called a lot but it's worth remembering that the dict() way of creating a dictionary requires more bytecode instructions, including a function call. \n\nIn [3]: dis.disassemble(compile('x = {}', '', 'single'))\n 1 0 BUILD_MAP 0\n 3 STORE_NAME 0 (x)\n 6 LOAD_CONST 0 (None)\n 9 RETURN_VALUE \n\nIn [5]: dis.disassemble(compile('x = dict()', '', 'single'))\n 1 0 LOAD_NAME 0 (dict)\n 3 CALL_FUNCTION 0\n 6 STORE_NAME 1 (x)\n 9 LOAD_CONST 0 (None)\n 12 RETURN_VALUE ", "group_id": 292, "id": 427704}, {"user_id": 24439, "stars": [], "topic_id": 14424, "date_created": 1300981622.2269189, "message": "@mjs0 Fair enough. As you say, I definitely don't think it's a bad thing to understand how it works, as long as it's not the first thing you think of when deciding \"how should I write this code?\" :)", "group_id": 292, "id": 427945}, {"user_id": 5773, "stars": [{"date_created": 1300984116.7625041, "user_id": 5778}, {"date_created": 1301153132.2554591, "user_id": 12791}], "topic_id": 14424, "date_created": 1300981544.978435, "message": "@mithrandi Sure, this should rarely be a consideration when choosing how you initialise a dict - in most cases readability is much more important. IMHO it's still worth understanding this anyway.", "group_id": 292, "id": 427930}, {"user_id": 8391, "stars": [], "topic_id": 14424, "date_created": 1300987793.0609059, "message": "@sshirokov: I had no idea you could do that", "group_id": 292, "id": 428947}, {"user_id": 7, "stars": [{"date_created": 1300995346.7170529, "user_id": 141}, {"date_created": 1301083461.868638, "user_id": 8391}], "topic_id": 14424, "date_created": 1300993945.8853159, "message": "CPython sucks blah blah", "group_id": 292, "id": 430004}, {"user_id": 1736, "stars": [{"date_created": 1301052194.4648271, "user_id": 1243}, {"date_created": 1301083464.7080081, "user_id": 8391}], "topic_id": 14424, "date_created": 1300997395.4747629, "message": "@alex Respect your elders youngun!", "group_id": 292, "id": 430512}, {"user_id": 7, "stars": [], "topic_id": 14424, "date_created": 1301032175.9573531, "message": "@coderanger Actually the funny part is it's better than most other interpreters out there. I'd have said MRI sucks, but I'm told it's rude to beat up on the disabled", "group_id": 292, "id": 436124}, {"user_id": 1736, "stars": [], "topic_id": 14424, "date_created": 1301034694.2404971, "message": "@alex This is true, the guts of YARV still give me the willies.", "group_id": 292, "id": 436295}, {"user_id": 25361, "stars": [], "topic_id": 14424, "date_created": 1301078378.5240469, "message": "I find the first form a lot more readable, I faster recognize it as a dict and not a random function call.", "group_id": 292, "id": 441113}] |