The sine function is one of the most fundamental concepts in mathematics, connecting geometry, trigonometry, and real-world applications. In its simplest form, sine is defined in a right triangle as the ratio of the length of the side opposite an…
The Rule of 114 is a quick way to estimate how long it will take to triple your money with compound interest. The idea is simple: divide 114 by the annual interest rate (in %), and you will get an…
The field of geometry offers tools that have withstood the test of time, empowering us to understand and solve a variety of triangular problems. Among these, the Pythagorean Theorem and the Law of Cosines are cornerstone concepts. This article provides…
There is something interesting about linear regression. I have just noticed, that I have actually quite some articles on it some years ago, but today I wanted to make a YouTube video as well. Well, what is the difference this…
So, what exactly is standard deviation? In simple terms, it’s a measure of how spread out the numbers in a dataset are from the mean or average. If the numbers are close to the mean, the standard deviation is small.…
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…
Some time ago, I wrote an article about defaultdict in Python here – vitoshacademy.com/python-defaultdict-object-or-how-to-avoid-the-key-error. Now, I have decided to make a video about it and increase the scope with standard dictionary functions and an advanced class, that checks whether the…
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.