Pradeep Elance

Pradeep Elance

317 Articles Published

Articles by Pradeep Elance

Page 26 of 32

How to Count Number of Files and Subdirectories inside a Given Linux Directory?

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 3K+ Views

When working with Linux systems, it's essential to know how to count files and subdirectories within a given directory. Python provides several ways to accomplish this task, from using the os module to leveraging the pathlib library for more modern approaches. Using os.walk() for Recursive Counting The os.walk() function recursively traverses directories and provides separate counts for files and subdirectories ? import os def count_files_and_dirs(directory): file_count = 0 dir_count = 0 for root, dirs, files in os.walk(directory): ...

Read More

How to Copy File Permissions and Ownership to Another File in Linux?

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 1K+ Views

When backing up data or configuring software in Linux, you often need to maintain the same ownership and permissions across files. Instead of manually setting permissions for each file, Linux provides efficient methods to copy these attributes from one file to another using the chown and chmod commands with the --reference option. Copying File Ownership Use the --reference switch with chown to copy ownership from a source file to a target file ? Syntax chown --reference=source_file target_file Example Let's copy ownership from ref_file.txt to all_rivers.txt ? # Check current ownership ...

Read More

Create Shortcuts to Long and Complicated Paths in Linux (Gogo)

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 198 Views

Gogo is a tool to bookmark directories with long and complicated paths in the Unix shell. Because the long paths are difficult to remember and cumbersome to type in, gogo provides a simple way to create shortcuts. In this article we'll see how to install gogo and use it. Installing Git We first need to have git installed in our system which will be needed for gogo installation. To install git in an Ubuntu system follow the below command ? $ sudo apt install git Running the above code gives us the following result ...

Read More

Python - Column summation of tuples

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 346 Views

Python has extensive availability of various libraries and functions which make it so popular for data analysis. We may get a need to sum the values in a single column for a group of tuples for our analysis. So in this program we are adding all the values present at the same position or same column in a series of tuples. Column summation involves adding corresponding elements from tuples at the same positions. For example, if we have tuples (3, 92) and (25, 62), the column summation would be (28, 154). Using List Comprehension and zip() Using ...

Read More

max() and min() in Python

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 2K+ Views

Finding maximum and minimum values from a given list of values is a very common need in data processing programs. Python provides built-in max() and min() functions that handle both numbers and strings efficiently. Syntax max(iterable, *[, key, default]) min(iterable, *[, key, default]) Using max() and min() with Numeric Values Both functions work with integers, floats, and mixed numeric types to find the maximum and minimum values ? numbers = [10, 15, 25.5, 3, 2, 9/5, 40, 70] print("Maximum number is:", max(numbers)) print("Minimum number is:", min(numbers)) Maximum number is: ...

Read More

Getter and Setter in Python

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 21K+ Views

In Python, getters and setters are methods used to control access to an object's attributes. They provide a way to implement data encapsulation, ensuring that attributes are accessed and modified in a controlled manner. Getters retrieve the value of an attribute, while setters allow you to modify it. This approach helps prevent direct manipulation of attributes from outside the class. Basic Class with Public Attributes Let's start with a simple class that has a public attribute − class YearGraduated: def __init__(self, year=0): self.year ...

Read More

Fractal Trees in Python

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 1K+ Views

Fractal patterns are everywhere in nature − a small branch resembles the entire tree, a fern leaf's part looks like the whole leaf. This self-repeating pattern concept is called a fractal tree. Python provides several modules to generate beautiful fractal trees programmatically. What is a Fractal Tree? A fractal tree is a mathematical structure that exhibits self-similarity at different scales. Each branch splits into smaller branches following the same pattern, creating a recursive tree-like structure. The recursion continues until reaching a specified depth. Using pygame Module The pygame module provides graphics functions to draw fractal trees. ...

Read More

Append Odd element twice in Python

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 280 Views

Sometimes we need to process a list where odd numbers appear twice while even numbers remain unchanged. This is useful in data processing scenarios where odd values need special emphasis or duplication. Using List Comprehension The most concise approach uses list comprehension with conditional repetition ? numbers = [2, 11, 5, 24, 5] # Repeat odd numbers twice, keep even numbers once result = [value for num in numbers for value in ([num] if num % 2 == 0 else [num, num])] print("Original list:", numbers) print("After processing:", result) Original list: [2, ...

Read More

Append at front and remove from rear in Python

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 305 Views

When working with Python lists, we often need to add elements to the front and remove elements from the rear. Python provides several efficient methods to accomplish this task, both from the standard library and through built-in operators. Using + Operator with List Slicing The simplest approach combines list concatenation with slicing to add an element at the front while removing the last element ? days = ['Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] print("Original list:", days) # Add 'Mon' at front and remove last element result = ['Mon'] + days[:-1] print("After append front and remove ...

Read More

Adding a Chartsheet in an excel sheet using Python XlsxWriter module

Pradeep Elance
Pradeep Elance
Updated on 15-Mar-2026 552 Views

The XlsxWriter module in Python is a powerful external library that allows you to create Excel files with data, formatting, and charts. Unlike Python's built-in libraries, XlsxWriter specializes in generating Excel files with advanced features like charts, images, and complex formatting. What is a Chartsheet? A chartsheet is a separate worksheet in Excel that contains only a chart, without any data cells. This is different from inserting a chart into a regular worksheet − the entire sheet becomes the chart. Creating a Pie Chart in a Chartsheet Let's create a pie chart that displays data about ...

Read More
Showing 251–260 of 317 articles
« Prev 1 24 25 26 27 28 32 Next »
Advertisements