New answers tagged

0

The quick fix would be to serialize into JSON and then hash that single string whichever way you please. That tends to be pretty stable, but there may be corner cases where it is not giving optimal results, for example when the object has arrays where the order of items may vary. Depends on how cleverly implemented hash() is for your parameter object. ...


0

The other answers list useful datastructures written from scratch, but it's also useful to extend the abilities of existing datastructures. I like to use namedtuples for simple immutable data and SimpleNamespaces for simple mutable data, but they are missing useful features. SimpleNamespaces for example don't allow iteration and don't have access via .keys()...


3

It ultimately comes down to a matter of perspective. List comprehensions, which is what your python example uses, tackle the idea of generating an array from a loop by putting the loop inside the array syntax. If this was possible in C, it'd look more like this: // clamped_list = [ max(64, min(128, i)) for i in source_list ] int clamped_list[16] = { max(...


7

C does not have lists as part of the language, and definitely no list comprehensions. That's why you have to operate on arrays/vectors using indexes, or allocate or declare them explicitly, which makes the whole section a little bit more clumsy. But if you reorder the very same statements you showed in your C example into a loop body like this for (i=0; i&...


0

How do you start the program? If you are starting from ground zero you may as well start by understanding the script you use to launch the program. That will lead you to the entry point, and you can branch out from there. Or are you saying that this code is so poorly documented that you don't even know how to launch the program? If that's the case, don't ...


2

A web app is an application accessible through the web. One possible way of doing a web app is to have a front end (that's the part that presents the application for use in a web browser, including those parts of web server code that provide HTML pages and assets) and a back end which implements the logical functionality of the application. In your specific ...


0

I've come to the conclusion through both Bart van Ingen Schenau's answer and also this answer suggested in a comment by John Wu, that ideally there should be validation in all layers of the platform. My plan is to have an error attribute on UsersDB() that is set when a method() returns False. The service object can then access the error to get the reason.


1

If you want to keep the validation logic out of UserService, but keep the reporting of errors to the user contained within that class, then you should look at other ways to internally communicate validation failures, rather than a boolean return value. Either the UserDb methods should return an error code, or they should throw an exception for validation ...


1

This is not great design. For starters it would be less efficient to enumerate the range. The code you provided would produce the same result as this: d = {} for i in range(4): d[i] = i ** 2 I would recommend trying variations out in the python console. The advantage your code has over this is that it sets up i and v so if you did want to modify ...


1

Reading data into an array requires allocating memory and means that you don't start comparing the data until you've finished loading the files. This, in theory, will take longer that comparing the data as it is read in. It also (naturally) requires more memory. For such a small amount of data, this is not really a major concern however. Unless you are ...


0

A complex question. On the face of it, yeah, if you have a websocket connection open, you should use it for everything. If you app has a limited set of functionality which is all served by a single back-end application, and websocket is working for you already, then this is going to be fine. However. What if your get history API is a separate application. ...


1

You can write a function that validates the data, and decorate the functions you want. If you can express your test as a python function: def has_columns(df, columns): """ Checks whether all `columns` are in `df` Retuns a boolean result and the missing columns """ if isinstance(columns, str): # to prevent the later `set` ...


0

You can assert the .dtypes or the individual df.column.dtype. Alternatively, while .astype() is used to convert datatype of columns, you can also use it to document the schema of data, by defining what columns are available and the types of those columns. The dtypes can also be specified in the dataframe constructor.


1

My first idea would be to include type hints and descriptive docstrings to functions responsible for loading a pandas DataFrame, e.g.: import pandas as pd def load_client_data(input_path: str) -> pd.DataFrame: """Loads client DataFrame from a csv file, performs data preprocessing and returns it. The client DataFrame is formatted as follows: ...


1

Yes, Yes, and Yes You have struck on all the ways for passing information around. Construct a container and refer to it everywhere Pass many, many arguments through the function signature Construct an Agent and have them solve retrieving the information based on a request. There really isn't a best way. What might be reasonable will depend on the ...


2

I don't know how"they" do it, but I have applied ML to a real-time problem (spam mail detection based on data available in the SMTP dialog, i.e. before the actual message is transmitted.) One thing is that training and applying a neural network are fundamentally different operations. Training is iterative and requires careful selection of network ...


1

You should implement this as two columns, and use two rows for reciprocal permissions. Barring some exotic circumstances, this situation is better designed as a table with two columns - one for the permission holder, and one for the subject. If you need reciprocal permissions, you'll have two rows on said table. (as pointed out by @AntP). A table having a ...


2

The PEP-8 style guide suggests using lowercase with underscores for function names. Incidentally, this style is also known as snake_case. Coincidence, or irony? :) So if you wish to follow those conventions, then args_to_filename is a good choice. Of course, such guidelines are just that: a guide. As long as you are consistent with your own convention, ...


-1

I think it could be better to use it in a generic form so you convert some args to a specific format. simply say toYourFormat in your case you can keep on saying toFileName but if you found a more generic name it can be better. But anyway I think your design could be better if these args was instead a class that toFileName is a method of it and the class is ...


0

Here's some associations care of google autocomplete surrounding base python... base python packages base python libraries


Top 50 recent answers are included