Programming Articles

Page 134 of 2547

Python Program To Get The Middle Element Of A Linked List In A Single Iteration

Kavya Elemati
Kavya Elemati
Updated on 27-Mar-2026 2K+ Views

A linked list stores data in non-contiguous memory locations using nodes connected by pointers. Each node contains data and a link to the next node. Finding the middle element efficiently requires the two-pointer technique to avoid multiple iterations. Brute Force Approach The brute force method requires two passes through the linked list ? First pass: Count total nodes to find length Second pass: Traverse to the middle position (length/2) Time complexity: O(n), but requires two iterations Two-Pointer Technique (Single Iteration) This optimal approach uses slow and fast pointers moving at different speeds ? ...

Read More

Python Program To Add Elements To A Linked List

Kavya Elemati
Kavya Elemati
Updated on 27-Mar-2026 1K+ Views

A linked list is a linear data structure where elements are stored in nodes, and each node contains data and a reference to the next node. Unlike arrays, linked list elements are not stored in contiguous memory locations, making insertion and deletion operations more efficient. In Python, we can implement a linked list using classes. Each node contains data and a pointer to the next node. The first node is called the head, and the last node points to None. Linked List Structure Every node in a linked list contains ? Data − The actual ...

Read More

Python Program to get first and last element from a Dictionary

Utkarsha Nathani
Utkarsha Nathani
Updated on 27-Mar-2026 25K+ Views

Python dictionaries are ordered collections (as of Python 3.7+) that store data as key-value pairs. When working with dictionaries, you might need to access the first and last elements. This article demonstrates multiple methods to retrieve these elements efficiently. Dictionary Basics A dictionary is a collection of items that are unique, changeable, and ordered. Since Python 3.7, dictionaries maintain insertion order, meaning items retain the order in which they were added. # Example dictionary student_data = {'Name': 'Akash', 'Roll': '3', 'Subject': 'Bio'} print(student_data) {'Name': 'Akash', 'Roll': '3', 'Subject': 'Bio'} Using list() ...

Read More

Python program to remove null values from a dictionary

Utkarsha Nathani
Utkarsha Nathani
Updated on 27-Mar-2026 3K+ Views

Dictionaries are collection data types that store data as key-value pairs. They are ordered, changeable, and do not allow duplicate keys. Sometimes dictionaries contain null values (represented by None in Python) that need to be removed for data processing. In this article, we will explore different methods to remove None values from dictionaries using Python. Understanding None Values in Python In Python, None represents the absence of a value. Unlike other languages that use "null", Python uses None as a first-class object. It's commonly used as default parameter values, placeholder values, or when functions don't explicitly return ...

Read More

Python Program To Find The Largest Element In A Dictionary

Utkarsha Nathani
Utkarsha Nathani
Updated on 27-Mar-2026 414 Views

Dictionaries are used to store data values in key:value pairs like maps. Unlike other data types that hold only a single value as an element, dictionaries provide key:value pairs to make data access more effective. Dictionary keys must be unique, so no duplicate keys are allowed. Dictionary items are ordered, changeable, and immutable. Changeable means we can add or remove items after the dictionary is created. In this article, we will learn how to find the largest element in a dictionary using different methods like loops, sorted(), max() function, and comparison operators. Methods to Find the Largest ...

Read More

Python Program to Search an Element in a Dictionary

Utkarsha Nathani
Utkarsha Nathani
Updated on 27-Mar-2026 20K+ Views

Dictionaries are used to store data values in key:value pairs. Keys are unique and dictionaries are ordered, changeable, and allow you to quickly find values using their corresponding keys. In this article, we will explore different methods to search for elements in a dictionary. You can search by value to find the corresponding key, or check if a key exists in the dictionary. Common Search Operations Here are the main methods to search elements in a dictionary ? Using "for" loop with "in" operator Using items() with list comprehension Using a custom function with items() ...

Read More

Python Program to Add Elements to a Dictionary

Utkarsha Nathani
Utkarsha Nathani
Updated on 27-Mar-2026 287 Views

Python dictionaries are versatile data structures that store data as key-value pairs. Adding elements to dictionaries is a common operation with several approaches, each suited for different scenarios. What is a Python Dictionary? A dictionary in Python stores key-value pairs, where each key must be unique and immutable (strings, integers, tuples). Values can be of any data type and may be repeated. Syntax {key1: value1, key2: value2, key3: value3} Example # Creating a simple dictionary student = {'name': 'Alice', 'age': 20, 'grade': 'A'} print(student) {'name': 'Alice', 'age': 20, ...

Read More

Python Program To Create A Dictionary With A Dictionary Literal

Utkarsha Nathani
Utkarsha Nathani
Updated on 27-Mar-2026 1K+ Views

Dictionaries are used to store data values in key:value pairs. Unlike other data types that hold only a single value as an element, dictionaries use key-value pairs to make data access more effective. Dictionary keys must be unique, so no duplicate keys are allowed. Dictionary items are ordered (as of Python 3.7+), changeable, and mutable. This means we can add or remove items after the dictionary is created. Creating a Dictionary with Dictionary Literals We can create a dictionary using curly brackets {}. Place elements inside curly brackets, separate keys and values with colons :, and separate ...

Read More

Python program to convert list of string to comma separated string

Utkarsha Nathani
Utkarsha Nathani
Updated on 27-Mar-2026 617 Views

Python provides several methods to convert a list of strings into a comma-separated string. This is a common operation when you need to format data for display, CSV files, or string concatenation. Understanding the Problem When converting a list of strings to a comma-separated string, each element becomes part of a single string with commas as separators. For example, ["apple", "banana", "cherry"] becomes "apple, banana, cherry". Method 1: Using join() The join() method is the most efficient and pythonic approach. It combines all elements of an iterable into a single string using a specified separator ? ...

Read More

Python program to remove null value from a list

Utkarsha Nathani
Utkarsha Nathani
Updated on 27-Mar-2026 12K+ Views

This article discusses how to remove None values from a Python list. In Python, None represents the absence of a value and is equivalent to "null" in other programming languages. Understanding None in Python None is a keyword in Python that represents an empty or missing value. It is not the same as 0, False, or an empty string ? # None is unique print(None == 0) # False print(None == False) # False print(None == "") # False ...

Read More
Showing 1331–1340 of 25,469 articles
« Prev 1 132 133 134 135 136 2547 Next »
Advertisements