Here is an explanation of the Central Limit Theorem (CLT) in a few simple points: Explanation: The Central Limit Theorem states that the distribution of the sample means (averages) of a large number of samples from any population will be…
Python code examples
Object oriented programming (OOP) in general is a huge topic, but I have decided to make a 30 minute video, based on the book Math for Programmers, as I liked the way it was explained there: Generally, in the video,…
Working with Python and Excel is actually quite handy, especially if you are into it. In this article, you can see how to create Excel files, write data and formulas into them and read these. Pretty much simple CRUD methods.…
In the previous article, the post and get API methods were presented. In this one, Put and Delete are coming. 🙂 Well, nothing that fancy, this is how these two methods look like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# Update item by id @app.route('/api/items/<int:item_id>', methods=['PUT']) def update_item(item_id): data = request.get_json() updated_data = data.get('item') # Get the nested 'item' data if not updated_data: return jsonify({'error': 'No data provided'}), 400 item = next((item for item in items if item['id'] == item_id), None) if item is None: return jsonify({'error': f'Item #{item_id} not found!'}) # Update fields in the item (dummy db) for key, value in updated_data.items(): if key in item: item[key] = value return jsonify({'message': 'Item updated successfully', 'item':item}), 200 # Delete item by id @app.route('/api/items/<int:item_id>', methods=['DELETE']) def delete_item(item_id): item_to_delete = next((item for item in items if item['id'] == item_id), None) if item_to_delete is None: return jsonify({'error': f'Item {item_id} not found!'}), 404 items.remove(item_to_delete) return jsonify({'message': f'Item: {item_to_delete} has been deleted successfully!'}), 200 |
And, of course tests are a…
Python allows decent built-in logging. As I am going to explain in the video below, the built-in logging is actually rather neat – it allows everyone to log into a file or into the console within minutes – just the…
This is probably a python “feature” that every junior developer has bumped into – once you make an empty list as a default argument in Python, it works as expected only for the first object of the class. For the second object – not exactly. Don’t worry, everyone has hit that bug, even it they are not willing to admit it.
Creamer’s rule for a solution of linear equations states pretty much the following: Using this interesting picture from the German Wikipedia, I have created the following video, explaining a bit the Rule of Mr. Cramer: The video goes through the…
Same article, but for VBA is here – https://www.vitoshacademy.com/vba-split-worksheet-to-worksheets-save-excel-worksheets-to-csv/ This article does 2 things: Splits one worksheet to multiple worksheets Then goes through the worksheets and saves them as *.CSV files So what is the idea? Having this excel file,…
Reading from a pdf is actually quite an easy task with Python. If the PDF is of course “readable”, e.g. made from a word processor. The first thing to do is to install Tika and Java:
1 2 3 |
pip install tika <em>conda install</em> -c conda-forge <em>tika # as alternative</em> java --version #this one checks the installed java version in the command prompt |
Having this, the…
If you have ever dreamed that it will be possible to fill out an Excel cell with a picture, using Python, then you should probably reevaluate your dreams. Seriously, who dreams of something like that? Without further dreaming, the code…
Python – Docstring – Help and Comments
Docstrings in Python are actually quite simple – the are 3 times this """ and the code between opening and closing them can be formatted in any possible way. The reason I have decided to dedicate a whole article to…