Found 10784 Articles for Python

Python - Accessing Items in Lists Within Dictionary

Priya Sharma
Updated on 14-Aug-2023 15:47:09

1K+ Views

Python is a versatile and widely used programming language known for its simplicity and readability. It offers a plethora of powerful data structures to efficiently handle and manipulate complex data. This feature enables you to organize data in a structured manner. In this blog post, we will delve into the process of accessing items in lists within a dictionary using Python. We will explore various techniques to retrieve and modify data, providing you with a comprehensive understanding of this fundamental concept. Creating a Dictionary with Lists Before we dive into accessing items, let's start by creating a dictionary that contains ... Read More

Passing a Dictionary as Arguments to a Function in Python

Priya Sharma
Updated on 14-Aug-2023 15:48:13

4K+ Views

Python is a powerful and versatile programming language that provides a wide range of data structures to handle complex data. They offer a flexible and efficient way to organize and manipulate information, making them a popular choice for various programming tasks. This capability is especially useful when dealing with complex data structures or when you need to pass multiple related values to a function without explicitly defining numerous individual parameters. Accessing Dictionary Values within a Function Once the dictionary is passed as an argument, you can access its values using the keys within the function. This allows you to retrieve ... Read More

Map vs For Loop in Python

Priya Sharma
Updated on 14-Aug-2023 15:49:35

694 Views

Python provides programmers with several tools and techniques to manipulate data efficiently. Two commonly used approaches for iterating over a collection and performing operations on its elements are map() and for loops. While both methods have their merits, they differ in terms of syntax, functionality, and performance. In this blog post, we will explore the characteristics of map() and for loops, and discuss their best use cases to help you make an informed decision when choosing between the two. Understanding Map map() is a built-in Python function that applies a given function to each item of an iterable (e.g., a ... Read More

Iterating With Python Lambda

Priya Sharma
Updated on 14-Aug-2023 15:50:13

2K+ Views

In the world of Python programming, developers often encounter situations where they need to apply a function to every element of a list or an iterable. Traditionally, this involves writing a loop to iterate through the elements and apply the function one by one. However, Python provides a concise and powerful tool called lambda functions, also known as anonymous functions, which allow us to perform iterative operations without the need for explicit loops. In this blog post, we will explore the concept of iterating with Python lambda and discover its usefulness in various scenarios. Understanding Lambda Functions Before diving into ... Read More

Inplace Editing using Python FileInput

Priya Sharma
Updated on 14-Aug-2023 13:12:21

1K+ Views

Inplace editing is a technique that allows us to modify the contents of a file directly, without the need for creating a new file or loading the entire file into memory. It offers a streamlined approach to file manipulation by allowing us to make changes directly to the existing file, making it an efficient and resource-friendly method. To facilitate inplace editing in Python, the fileinput module comes into play. The fileinput module, part of the Python standard library, provides a high-level interface for reading and writing files, streamlining the process of inplace editing. With the fileinput module, we can open ... Read More

Index-based Operation in PyTorch

Priya Sharma
Updated on 14-Aug-2023 13:10:01

1K+ Views

Index-based operations play a vital role in manipulating and accessing specific elements or subsets of data within tensors. PyTorch, a popular open-source deep learning framework, provides powerful mechanisms to perform such operations efficiently. By leveraging index-based operations, developers can extract, modify, and rearrange data along various dimensions of a tensor. Tensor Basics PyTorch tensors are multi-dimensional arrays that can hold numerical data of various types, such as floating-point numbers, integers, or Boolean values. Tensors are the fundamental data structure in PyTorch and serve as the building blocks for constructing and manipulating neural networks. To create a tensor in PyTorch, we ... Read More

How to Call a Parent class method in Python ?

Priya Sharma
Updated on 14-Aug-2023 13:05:46

10K+ Views

In object-oriented programming, inheritance allows you to create new classes based on existing ones, providing a way to reuse code and organize your program's structure. Python, being an object-oriented language, supports inheritance and allows you to override methods defined in parent classes in child classes. However, there may be situations where you want to leverage the functionality of a parent class method while extending or modifying it in the child class. Method Overriding in Python Before we learn about calling parent class methods, let's briefly discuss method overriding. Method overriding is a feature in object-oriented programming that allows a ... Read More

Get the List of all empty Directories in Python

Priya Sharma
Updated on 14-Aug-2023 13:01:49

782 Views

When working with file systems and directories in Python, it's often useful to be able to identify and handle empty directories. Empty directories can accumulate over time, taking up unnecessary space or cluttering the directory structure. Being able to programmatically find and handle these empty directories can help streamline file system operations and improve overall organization. In this tutorial, we will explore different methods to obtain a list of all empty directories using Python. We will cover two approaches: the first using the os.walk() function, and the second utilizing the os.scandir() function. Both methods are efficient and provide different benefits ... Read More

Functional Transforms for Computer Vision using PyTorch

Priya Sharma
Updated on 14-Aug-2023 15:51:07

120 Views

Computer vision tasks often require preprocessing and augmentation of image data to improve model performance and generalization. PyTorch, a popular deep learning framework, provides a powerful library for image transformations called torchvision.transforms. This library offers a wide range of predefined transforms for data augmentation and preprocessing. However, in some cases, predefined transforms may not be sufficient, and we need to apply custom transformations to our image data. In this blog post, we will explore the concept of functional transforms in PyTorch and demonstrate how to create and apply custom transforms for computer vision tasks. Understanding Transforms in PyTorch Transforms in ... Read More

Finding All substrings Frequency in String Using Python

Priya Sharma
Updated on 14-Aug-2023 12:54:48

192 Views

String manipulation and analysis are fundamental tasks in many programming scenarios. One intriguing problem within this domain is the task of finding the frequency of all substrings within a given string. This article aims to provide a comprehensive guide on efficiently accomplishing this task using the powerful Python programming language. When working with strings, it is often necessary to analyze their contents and extract valuable information. The frequency of substrings is an important metric that can reveal patterns, repetitions, or insights into the structure of the string. By determining how many times each substring appears in a given string, we ... Read More

Advertisements