Found 33676 Articles for Programming

How to Remove All Directories and Files in Golang?

Sabid Ansari
Updated on 25-Apr-2023 17:57:29

5K+ Views

When working with large sets of data or files, it's important to have the ability to clean up your directory tree quickly and efficiently. This is where the power of Golang comes into play. In this article, we'll explore how to remove all directories and files in Golang, using various techniques and best practices. First, let's start with the basics. Golang provides a built-in package called "os" that provides functions for handling operating system-related tasks, such as file operations. In order to remove a file or directory in Golang, we can use the os.Remove() or os.RemoveAll() functions, respectively. os.Remove() function ... Read More

How to Read File Word By Word in Golang?

Sabid Ansari
Updated on 25-Apr-2023 17:57:14

778 Views

When working with files in Go, it is often necessary to read them word by word. In this article, we will explore how to read a file word by word in Golang. We will discuss three different approaches to accomplish this task and provide code snippets to demonstrate each method. Approach 1: Using bufio.NewScanner The first approach is to use the bufio package and its NewScanner function to read the file word by word. This function takes an io.Reader interface as input and returns a Scanner object that can be used to scan the file word by word. Example Here ... Read More

How to Print Specific date-time in Golang?

Sabid Ansari
Updated on 25-Apr-2023 09:37:42

2K+ Views

Go is a programming language that is well-suited for building high-performance, concurrent applications. One of the essential features of any application is the ability to work with date and time. In this article, we will explore how to print specific date-time in Go using the time package. Using the Time Package in Go The time package in Go provides a variety of functions for working with dates, times, and durations. The time.Time type represents a specific moment in time, and we can use its methods to format dates and times according to a specific layout. To print a specific date-time ... Read More

How to pause the execution of current Goroutine?

Sabid Ansari
Updated on 25-Apr-2023 17:37:03

2K+ Views

As a Go developer, you may need to pause the execution of a Goroutine at some point. Pausing the Goroutine can be helpful in scenarios such as waiting for input from the user, waiting for a response from a server, or to prevent a race condition. In this article, we will explore various methods to pause the execution of the current Goroutine in Go. Method 1: Using time.Sleep() The simplest way to pause the execution of the Goroutine is by using the time.Sleep() function. This function takes a duration as an argument and pauses the execution of the Goroutine for ... Read More

Python program to implement binary tree data structure

Kavya Elemati
Updated on 24-Apr-2023 16:58:47

456 Views

A tree is a data structure which consists of nodes. The nodes are connected by the edges. The top most node is called as the root and the bottom most nodes are called as the leaves. Leaves are the nodes that do not have any children. Binary Tree A binary tree is a tree in which every node can consist a maximum of 2 children. That means, every node can either have 0 or 1 or 2 children but not more than that. Every node in a binary tree consists of three fields − Data Pointer to the left ... Read More

Python Program To Detect A Loop In A Linked List

Kavya Elemati
Updated on 24-Apr-2023 17:37:46

978 Views

A linked list is said to have a loop when any node in the linked list is not pointing to NULL. The last node will be pointing to one of the previous nodes in the linked list, thus creating a loop. There will not be an end in a linked list that has a loop. In the below example, the last node (node 5) is not pointing to NULL. Instead, it is pointing to the node 3 and a loop is established. Hence, there is no end to the above linked list. Algorithm Take two pointers fast and slow ... Read More

Python Program To Convert An Array List Into A String And Viceversa

Kavya Elemati
Updated on 24-Apr-2023 16:54:40

256 Views

Converting a list into a string One method for converting a list into a string is to iterate through all the items of a list and concatenate them into an empty string. Example lis=["I", "want", "cheese", "cake"] str="" for i in lis: str=str+i str=str+" " print(str) Output I want cheese cake Using Join Function Join is an in-built function in python which is used for joining the items of an iterable object (ex: list) using a separator which will be specified by the user. We can use the join ... Read More

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

Kavya Elemati
Updated on 24-Apr-2023 17:24:17

1K+ Views

Linked list is used for storing the data in non-contiguous memory locations. The nodes containing the data items are linked using pointers. Each node consists of two fields. The first field is used for storing the data and the second field contains the link to the next node. Brute Force Technique To find the middle element of a linked list, the brute force technique is to find out the length of the linked list by iterating the entire linked list till NULL is encountered and then the length is divided by 2 to get the index of the middle element. ... Read More

Collections in Python

Kavya Elemati
Updated on 24-Apr-2023 16:47:24

5K+ Views

In python, collections are the containers used for storing the data. The built-in data structures in python are tuples, lists, sets and dictionaries. The collections class will provide additional data structures apart from the built-in data structures. Some of the data structures in the ‘collections’ module − Counter namedTuple orderedDict defaultDict Deque chainMap Counter It is the type of collection in which the elements will be stored as dictionary keys and the counts will be stored as dictionary values. Whenever you want to calculate the frequency of any item in a list, traditionally you would use a ... Read More

Python Program To Add Elements To A Linked List

Kavya Elemati
Updated on 24-Apr-2023 16:44:53

1K+ Views

What is a Linked List When data is not stored in continuous memory locations, it takes a lot of time to search all the memory locations to get the required data. To prevent this, we use Linked Lists. A linked list in Python is a data structure that stores items in an ordered sequence. It consists of nodes, where each node contains the item and a reference to the next node in the list. The first node is known as the head, while the last one is referred to as tail. Linked lists are used for efficient insertion and deletion ... Read More

Advertisements