Earlier quoted context omitted.
> can't even use a dict as a dict key Curious, is this actually something you want to do often? While there is no hashable+immutable frozendict ala frozenset, you could throw one together or even define a hash function on a subclass and "swim at your own risk" not to mutate it later. I've encountered this enough with lists and the obvious solution is to cast them to tuples. Can't say I've found the same with dicts th…
Several times, when working with Lua, I’ve made what I call “Janus tables”. Give them a string, they return a table or function. Give them the table or function, they return a string. It’s a useful technique that you can only apply if your hashmap can map anything to anything.
Python overtakes JavaScript as most questioned language on StackOverflow
61–70 of 166 posts
Re: Python overtakes JavaScript as most questioned language on StackOverflow
#62Earlier quoted context omitted.
15 years of Python here, started in 2.4. Day to day Python is not more complicated to use. It's actually easier due to many bugs fixes, quality of life features and better error messages. However, Python does provide more tools to do more complicated things (async, type hints, etc), but that's not what most people use. They actually don't even know about it, and don't have to care. So it's not the questions you see o…
I mostly agree with you, but still think that Python could be way simpler and equally powerful. I'd love to see a language similar to Python, but with named structs instead of classes, for instance.
Re: Python overtakes JavaScript as most questioned language on StackOverflow
#63Earlier quoted context omitted.
You don't really need a FrozenSet if you're already willing to iterate over this dictionary. You can just use a tuple, which is also hashable. tuple(d.items())
That depends on the order in which the values are are returned by items(), which you likely do not want. >>> tuple({1:2,3:4}.items()) == tuple({3:4,1:2}.items()) False >>> frozenset({1:2,3:4}.items()) == frozenset({3:4,1:2}.items()) True
Re: Python overtakes JavaScript as most questioned language on StackOverflow
#64Earlier quoted context omitted.
> can't even use a dict as a dict key Curious, is this actually something you want to do often? While there is no hashable+immutable frozendict ala frozenset, you could throw one together or even define a hash function on a subclass and "swim at your own risk" not to mutate it later. I've encountered this enough with lists and the obvious solution is to cast them to tuples. Can't say I've found the same with dicts th…
Absolutely. For me it is a 50-50 chance whether I have data in a dict that needs to be mapped to something or have data in a list/tuple that needs mapping. Many major programming languages undersell how natural key-value data structures are; usually by providing unwieldy mapping data types. Clojure has spoiled me. > you could throw one together Yeah, I do. Most Python programmers wouldn't see a need for that, but tha…
You're being extremely uncharitable here.
To a Python programmer "using a dict as a key" is a nonsensical idea for the same reason "using a list as a key" is — both dicts and lists are mutable. Python programmers don't think of dicts or lists as synonymous with their content.
I'm assuming you don't want to literally use a dict as a key, you want to use the keys and values contained in a dict as a key. Nothing stops you. You just have to say it:
point = dict(x=4, y=5, z=1)
point_reviews = dict()
point_reviews[tuple(point.items())] = "A+++ great coord would point to again"
You might wonder why you can't just use dicts directly. Again, dicts are mutable. What happens if you write: point = dict(x=0, y=9001)
point_reviews = dict()
point_reviews[point] = "Love how it's over 9000 here!"
point["y"] = 8999
result = point_reviews[dict(x=0, y=8999)] # Is this a KeyError or not?
More detail on this issue is explained here: https://wiki.python.org/moin/DictionaryKeysIn the simplest case where you have a predefined list of keys, I'd suggest using a namedtuple instead of a dict. If you need to treat a dict's content as hashable but can't enumerate the keys, `tuple(d.items())` is probably the best choice in recent Python versions. Be aware though that in older Pythons you can't rely on stable sort order of dictionary items, so you have to use something like `frozenset(d.items())`.
Re: Python overtakes JavaScript as most questioned language on StackOverflow
#65Type hints and annotations are a step in the right direction. But the adoption is still not high. That's the blessing and curse of Python - it supports many good practices but it doesn't force you to use them so it really depends on the programmer.
Re: Python overtakes JavaScript as most questioned language on StackOverflow
#66I like Python and it's my main language currently after years of C++ and Java. My main problem with Python is that it's really easy to create really messy code that no one can follow. And I see it often because everyone is using Python these days. For example, you have an undocumented function with 6 arguments and have no idea what these are (having bad names also doesn't help, but that's not a Python specific issue)…
Re: Python overtakes JavaScript as most questioned language on StackOverflow
#67Earlier quoted context omitted.
protip: you can also increase your StackOverflow clout by merely asking or answering the most generic basic questions. You'll look like a community expert and thought leader in no time. Helps the resume inhalers that weigh these arbitrary things. More complex questions about specific frameworks or how that might work with your ORM and memory cache just don't get the attention.
Do people really use StackOverflow for answering job-related programming questions? The only time I found the questions on there useful was when I was a first year student learning programming. Maybe I am just bad at searching / asking.
Some programming language and frameworks have more active communities on StackOverflow than others.
So in my sprints, I would typically have 3 tasks in progress at once: 1 I would work on myself, 1 would go on Stackoverflow waiting for the answer, and 1 would be something that required progress from a different team in the company (like a new API endpoint so I could do something on a frontend, or different service)
It was pretty efficient for me. In some communities, the real thought leaders and framework developers are on stack overflow, watching the hashtag like a hawk.
You can also use github issues on the actual package you have issue with pretty well too, alongside it.
So you're really crowdsourcing a lot, and evaluating if that solution is correct enough for your implementation.
But so many times, especially with frameworks, the answer is a good copy and paste job. your mileage and use case may vary.
Re: Python overtakes JavaScript as most questioned language on StackOverflow
#68Earlier quoted context omitted.
> can't even use a dict as a dict key Curious, is this actually something you want to do often? While there is no hashable+immutable frozendict ala frozenset, you could throw one together or even define a hash function on a subclass and "swim at your own risk" not to mutate it later. I've encountered this enough with lists and the obvious solution is to cast them to tuples. Can't say I've found the same with dicts th…
Several times, when working with Lua, I’ve made what I call “Janus tables”. Give them a string, they return a table or function. Give them the table or function, they return a string. It’s a useful technique that you can only apply if your hashmap can map anything to anything.
Any hashmap will have problems with storing mutable objects, where the hash value itself can change after the object has been stored, causing some very unwanted paradoxes.
And that is the problem with Python dicts as keys.
Re: Python overtakes JavaScript as most questioned language on StackOverflow
#69Python's documentation is not the worst, but it's certainly nowhere near the best. As for JavaScript, these days I almost entirely rely on the MDN documentation and hardly go to Stack Overflow for that topic.
Re: Python overtakes JavaScript as most questioned language on StackOverflow
#70In this sort of context, "most questioned" is probably not much more than a synonym for "most popular".
Couldn't disagree with you more. "most questioned" is some combination of: - many beginners - incomplete or outdated documentation - not taught (or taught well) in schools - SO users who don't search for old answers before posting again See how none of those things, even mixed together, are a good proxy for popularity? We don't know the mix of the above factors for Python, but without better analysis, the headline he…
I would expect advanced people to ask just as many questions as beginners (they just do more advanced stuff, and ask questions relating to more advanced things pertaining to the langauge). Good documentation does not stop people from asking questions, as questions are frequently asked to which "RTFM" is the answer. Schools? Actually pupils asking "do my homework" questions is probably a driver in the opposite direction.