✖️ DON'T CREATE NESTED LISTS WITH THE
Because of this, you create a list containing multiple references to the very same inner list.
It looks like you're making a grid, but modifying one row will surprisingly change all of them. This is because the outer list just holds copies of the reference, not copies of the list itself.
Correct — use a list comprehension to ensure each inner list is a new, independent object.
Subscribe for more Python secrets!
━━━━━━━━━━━━━━━
By: @DataScienceQ ✨
* OPERATOR.Because of this, you create a list containing multiple references to the very same inner list.
It looks like you're making a grid, but modifying one row will surprisingly change all of them. This is because the outer list just holds copies of the reference, not copies of the list itself.
Correct — use a list comprehension to ensure each inner list is a new, independent object.
Subscribe for more Python secrets!
# hidden error — all inner lists are the same object
matrix = [[]] * 3 # seems to create a 3x0 matrix
# append to the first row
matrix[0].append(99)
# all rows were modified!
print(matrix) # [[99], [99], [99]]
# ✅ correct version — use a list comprehension
matrix_fixed = [[] for _ in range(3)]
# append to the first row
matrix_fixed[0].append(99)
# only the first row is modified, as expected
print(matrix_fixed) # [[99], [], []]
━━━━━━━━━━━━━━━
By: @DataScienceQ ✨
❤5
🎁❗️TODAY FREE❗️🎁
Entry to our VIP channel is completely free today. Tomorrow it will cost $500! 🔥
JOIN 👇
https://news.1rj.ru/str/+MPpZ4FO2PHQ4OTZi
https://news.1rj.ru/str/+MPpZ4FO2PHQ4OTZi
https://news.1rj.ru/str/+MPpZ4FO2PHQ4OTZi
Entry to our VIP channel is completely free today. Tomorrow it will cost $500! 🔥
JOIN 👇
https://news.1rj.ru/str/+MPpZ4FO2PHQ4OTZi
https://news.1rj.ru/str/+MPpZ4FO2PHQ4OTZi
https://news.1rj.ru/str/+MPpZ4FO2PHQ4OTZi
❤2
Checking Memory Usage in Python
psutil is imported, then through psutil.virtual_memory() memory data is obtained.
The function convert_bytes converts bytes to gigabytes.
Then the code calculates:
- total RAM
- available RAM
- used RAM
- percentage usage
And outputs this to the console.
Or simply press CTRL + ALT + DELETE and open Task Manager. It has worked since the days of Windows 95.
The RAM usage percentage loses its meaning if you have Chrome open — it will consume everything on its own 😄
👉 https://news.1rj.ru/str/DataScienceQ
psutil is imported, then through psutil.virtual_memory() memory data is obtained.
The function convert_bytes converts bytes to gigabytes.
Then the code calculates:
- total RAM
- available RAM
- used RAM
- percentage usage
And outputs this to the console.
import psutil
memory = psutil.virtual_memory()
def convert_bytes(size):
# Convert bytes to GB
gb = size / (1024 ** 3)
return gb
total_gb = convert_bytes(memory.total)
available_gb = convert_bytes(memory.available)
used_gb = convert_bytes(memory.used)
print(f"Total RAM: {total_gb:.3f} GB")
print(f"Available RAM: {available_gb:.3f} GB")
print(f"Used RAM: {used_gb:.3f} GB")
print(f"RAM Usage: {memory.percent}%")
The RAM usage percentage loses its meaning if you have Chrome open — it will consume everything on its own
Please open Telegram to view this post
VIEW IN TELEGRAM
❤2
What can be a key in a dictionary?
Answer:
tags: #interview
Please open Telegram to view this post
VIEW IN TELEGRAM
❤4👏3
Why does
isinstance(True, int) return True?Answer:
tags: #interview
Please open Telegram to view this post
VIEW IN TELEGRAM
❤6👍1
Forwarded from Machine Learning with Python
Our Group on Signal (only for Programmers)
https://signal.group/#CjQKIPcpEqLQow53AG7RHjeVk-4sc1TFxyym3r0gQQzV-OPpEhCPw_-kRmJ8LlC13l0WiEfp
https://signal.group/#CjQKIPcpEqLQow53AG7RHjeVk-4sc1TFxyym3r0gQQzV-OPpEhCPw_-kRmJ8LlC13l0WiEfp
What is Big O notation?
Answer:
For example, O(n) grows linearly, O(n²) - quadratically, O(1) - does not depend on the size of the input.
Big O does not give exact figures, but allows you to compare algorithms in terms of their scalability.
tags: #interview
Please open Telegram to view this post
VIEW IN TELEGRAM
❤7
What is
__slots__?Answer:
There is one restriction: it is not possible to add an attribute that is notslotsts__. To retain the ability to dynamically create fields, you can dictct__ to the list of slots.
tags:
Please open Telegram to view this post
VIEW IN TELEGRAM
❤5👎1
❗️LISA HELPS EVERYONE EARN MONEY!$29,000 HE'S GIVING AWAY TODAY!
Everyone can join his channel and make money! He gives away from $200 to $5.000 every day in his channel
https://news.1rj.ru/str/+YDWOxSLvMfQ2MGNi
⚡️FREE ONLY FOR THE FIRST 500 SUBSCRIBERS! FURTHER ENTRY IS PAID! 👆👇
https://news.1rj.ru/str/+YDWOxSLvMfQ2MGNi
Everyone can join his channel and make money! He gives away from $200 to $5.000 every day in his channel
https://news.1rj.ru/str/+YDWOxSLvMfQ2MGNi
⚡️FREE ONLY FOR THE FIRST 500 SUBSCRIBERS! FURTHER ENTRY IS PAID! 👆👇
https://news.1rj.ru/str/+YDWOxSLvMfQ2MGNi
❤2
What is a message broker and which ones are typically used with Python?
Answer:
In Python projects, RabbitMQ, Apache Kafka, and Redis are often used as simple broker solutions (for example, in combination with Celery). The choice depends on the tasks: Kafka for stream processing, RabbitMQ for flexible routing, and Redis for simple queues.
tags: #interview
Please open Telegram to view this post
VIEW IN TELEGRAM
❤3
“I didn’t believe it at first…” But after just a few weeks, I earned over $800 copying a simple crypto method. Many start skeptical — now they’ve found a steady income. Are you ready to stop watching others win? Discover how here before it’s too late! ✈️
#ad InsideAds
#ad InsideAds
❤1