Tag Info

New answers tagged

0

Some considerations regarding the second part of the question: Is it just a poor design choice (if it is a good one, please explain)? For example in scala, you can chain collection methods like smth.map(func1).reduce(func2). It seems much more convenient to me. I do not think that it is poor design: Python supports both procedural and ...


0

Which class would you put these methods on? In python, I can use map on lists, tuples, dictionaries, files, strings, sets, arrays, etc. There is no collection base class to put a map,reduce,filter etc on. Now, python could have had a collection class that all these different things inherited from. But that would really go against the "spirit" of python. In ...


0

I think this is just a historical artifact. These functions were introduced quite a while ago, when fluid interfaces were not all the rage. Since then everyone got used to them. (So yes, you can write it of as "bad design"). Could these functions could be retrofitted to lists? Possibly, but it was not and should not have been done. First, There should be ...


-1

My friend told me that there isn't a solution for this problem. You will propably have to stick with python 2 for now unless you want to implement it yourself.


-1

You should either write a python interpreter in Lua or you could use the SWIG. C could also be an option. Hope this helps.


4

If a function performs two tasks, or one task in two different ways, it should be two functions. This is the single responsibility principle. While the code may "compare strings" in both cases, the inputs might be different or the way in which it compares strings might be different. The keys to remember when thinking about it being "clever" to overload a ...


0

Django will help you in that manner. You will redirect multiple sites to your Django instance, and the Django instance will use the API that can help you with saving through economies of scale, with VM costs/ API subscription costs, etc. In this context, I am assuming that you are not using limited free tiers, or you do not have complicated SLAs with your ...


0

Yes. It is much better then how it was done previously. Moreover Django is also the right tool to do it. The reason for the same is, when we look at the base of the framework i.e. Django is this case is written in Python. Python believes more in Readability rather then writing the code itself. So, yes the things you have done is much better in simple terms ...


0

Looking through the documentation, I found this after searching the Django repository for re.compile. Look through django.core.urlresolvers. RegexURLResolver is called on the root urlconf unless it's set by whatever calls get_resolver. The output of get_resolver, and therefore the result of building the URL resolver, is cached: ...


3

The value of bob is 1 as of the first line of code which assigns 1 to a variable named bob. Then the string "bob" is assigned to the variable bob, replacing the value of 1. It's the same variable, just with different values. This is dynamic typing since the program will be type checked when these lines of code are executed. "Strong" and "Weak" typing are ...


-1

In terms of correctness, I think exception handling is the way to go (I sometimes use the hasattr() approach myself, though). The basic problem with relying on hasattr() is that it turns violations of code contracts into silent failures (this is a big problem in JavaScript, which doesn't throw on non-existing properties).


0

It depends which implementation of python you're going for. If you are targeting cpython (the python.org version), I'd recommend spending your time on getting the semantics of the program right. For other implementations you might want to read up on object caching, since you'll need it. For most languages with GCs, you have to be very careful with how you ...


0

check_duplicate is redundant. The list must not be sorted because sorting rearanges elements. Calculate the difference between two consecutive elements and compare the value against k. def check_distance(x, k): l = len(x) if l in [0,1]: return False for i in range(l-1): if x[i+1] - x[i] < k: return False ...



Top 50 recent answers are included