Articles on Trending Technologies

Technical articles with clear explanations and examples

Tutorix - AI Tutor

Python - Updating value list in dictionary

Arpana Jain
Arpana Jain
Updated on 27-Mar-2026 557 Views

In Python, dictionaries store data as key-value pairs where values can be lists. Updating these value lists is a common operation when working with dynamic data structures. Syntax dictionary_name[key] = new_value_list You can update a value list by assigning a new list to the specific key using the assignment operator (=). This replaces the existing list associated with that key. Method 1: Direct Assignment Replace the entire value list with a new list ? # Create a dictionary with initial values student_grades = { 'math': [85, 90, ...

Read More

Visualizing O(n) using Python

Arpana Jain
Arpana Jain
Updated on 27-Mar-2026 255 Views

Time complexity is a fundamental concept in computer science that measures how an algorithm's runtime changes as the input size grows. O(n) represents linear time complexity, where execution time increases proportionally with input size. Understanding and visualizing O(n) helps developers write efficient code and analyze algorithm performance. What is O(n) Time Complexity? O(n) indicates that an algorithm's execution time grows linearly with the input size 'n'. If you double the input, the execution time roughly doubles too. The most common example is a simple loop that processes each element once ? def linear_search(arr, target): ...

Read More

Python - Visualize graphs generated in NetworkX using Matplotlib

Arpana Jain
Arpana Jain
Updated on 27-Mar-2026 3K+ Views

NetworkX is a powerful Python library for creating, manipulating, and studying complex networks. When combined with Matplotlib, it provides excellent capabilities for visualizing graphs with customizable layouts, colors, and labels. Basic Graph Visualization The simplest way to visualize a NetworkX graph is using the draw() function with Matplotlib ? import networkx as nx import matplotlib.pyplot as plt # Create a simple graph G = nx.Graph() G.add_edge(1, 2) G.add_edge(2, 3) G.add_edge(3, 1) # Draw and display the graph nx.draw(G, with_labels=True, node_color='lightblue', node_size=500) plt.title("Basic Graph Visualization") plt.show() Visualizing Graphs with Node Labels and Edge ...

Read More

Python - Valid Ranges Product

Arpana Jain
Arpana Jain
Updated on 27-Mar-2026 224 Views

The valid ranges product problem involves finding the product of consecutive non-zero elements in a list, treating zeros as delimiters. This is useful in data processing and algorithmic challenges where you need to process segments of data separated by specific values. Problem Definition Given a list containing numbers and zeros, we need to ? Identify continuous sequences of non-zero numbers Calculate the product of elements in each valid sequence Return a list of all products For example, in [4, 9, 0, 0, 3, 4, 5, 0, 0, 4, 0], the valid ranges are [4, ...

Read More

Python - Use of slots

Arpana Jain
Arpana Jain
Updated on 27-Mar-2026 913 Views

Python's __slots__ is a class attribute that restricts which attributes can be assigned to instances, providing memory optimization and faster attribute access. By defining slots, Python avoids creating a __dict__ for each instance, significantly reducing memory usage. Syntax class MyClass: __slots__ = ('attr1', 'attr2', 'attr3') The __slots__ attribute accepts a tuple, list, or any iterable containing the names of allowed attributes. Once defined, instances can only have these specific attributes. Basic Usage of Slots Here's a simple example demonstrating how slots work ? class Person: ...

Read More

Python - URL Shortener using Tinyurl API

Arpana Jain
Arpana Jain
Updated on 27-Mar-2026 2K+ Views

In the web era, concise links are crucial for sharing hyperlinks via social media, text messages, and other communication methods. Long URLs can be challenging to share and might be truncated in messages. Python provides a convenient approach to interact with URL shortening services like TinyURL through their API. What is a URL Shortener? A URL shortener is a service that takes a long URL as input and generates a shorter, more manageable URL. This shortened URL redirects users to the original long URL when clicked. URL shorteners are widely used on social media, email communications, and any ...

Read More

Product of two Dictionary Keys in Python

Gajraj Singh Bhati
Gajraj Singh Bhati
Updated on 27-Mar-2026 310 Views

Finding the product of dictionary values in Python involves filtering dictionary entries based on specific conditions and then calculating the product of the filtered values. This is useful when you need to perform mathematical operations on subsets of dictionary data. Understanding Dictionary Structure A dictionary stores data as key-value pairs. Each key is unique and maps to a specific value ? fruits = { 'apple': 5, 'banana': 10, 'orange': 3, 'grape': 8 } print("Dictionary keys:", list(fruits.keys())) print("Dictionary values:", list(fruits.values())) ...

Read More

Product of Selective Tuple Keys in Python

Gajraj Singh Bhati
Gajraj Singh Bhati
Updated on 27-Mar-2026 224 Views

Sometimes we need to calculate the product of specific elements from a tuple based on their indices. This is useful in data processing scenarios where we want to multiply only selected values rather than all elements. Understanding Tuple Indexing A tuple is an ordered, immutable collection in Python. Each element has an index starting from 0 ? my_tuple = (2, 4, 6, 8, 10) print(f"Element at index 0: {my_tuple[0]}") print(f"Element at index 2: {my_tuple[2]}") print(f"Element at index 4: {my_tuple[4]}") Element at index 0: 2 Element at index 2: 6 Element at index 4: ...

Read More

Finding the Product of i^k in a List using Python

Gajraj Singh Bhati
Gajraj Singh Bhati
Updated on 27-Mar-2026 200 Views

Finding the product of elements raised to a power (i^k) in a list is a common mathematical operation in Python. This involves raising each element to a specific power and then multiplying all the results together. Understanding the Problem Given a list of numbers [2, 3, 4, 5] and a power k=2, we need to calculate 2² × 3² × 4² × 5² = 4 × 9 × 16 × 25 = 14400. This operation is useful in mathematical computations, statistical analysis, and engineering calculations. Method 1: Using functools.reduce() The reduce() function applies a function cumulatively ...

Read More

Finding the Product of Elements Using an Index List in Python

Gajraj Singh Bhati
Gajraj Singh Bhati
Updated on 27-Mar-2026 400 Views

In Python, you can find the product of specific elements from a list using their index positions. This is useful when you need to multiply only certain elements rather than the entire list. Understanding the Problem Given a list of numbers and a list of indices, we want to multiply only the elements at those specific positions. For example: Elements list: [1, 2, 3, 4, 5] Index list: [0, 2, 4] Elements at indices: 1, 3, 5 Product: 1 × 3 × 5 = 15 Using a Function Approach Here's a function that ...

Read More
Showing 931–940 of 61,297 articles
« Prev 1 92 93 94 95 96 6130 Next »
Advertisements