Tag: Numbers
Object Oriented Approach to Display a sequence of numbers without any For-Loop or Recursion
Suppose we have to display a sequence of numbers like from 10 to 20 i.e. 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 Advertisements without using any for-loop and recursion. Solution: Frequently Asked: Object Oriented Approach to Display a sequence of numbers without any For-Loop or Recursion We will use two concepts …
Object Oriented Approach to Display a sequence of numbers without any For-Loop or RecursionRead More
How to fill a vector with random numbers in C++
In this article we will discuss how to fill a std::vector with random numbers using std::generate. For this task we will use a STL algorithm std::generate i.e. Advertisements template<typename _FIter, typename _Generator> void generate(_FIter start, _FIter end, _Generator gen); It will update all the elements from range start to end -1 with values generated by …
Python : Sort a List of numbers in Descending or Ascending Order | list.sort() vs sorted()
In this article we will discuss how to sort a list of numbers in ascending and descending order using two different techniques. list.sort() vs sorted() list’s sort() function In Python, list provides a member function sort() that can sorts the calling list in place. Advertisements sorted() Function It’s a built in function that accepts an …
Python : Sort a List of numbers in Descending or Ascending Order | list.sort() vs sorted()Read More
numpy.arange() : Create a Numpy Array of evenly spaced numbers in Python
In this article we will discuss how to create a Numpy array of evenly spaced numbers over a given interval using numpy.arrange(). numpy.arrange() Python’s numpy module provides a function to create an Numpy Array of evenly space elements within a given interval i.e. numpy.arange([start, ]stop, [step, ]dtype=None) Arguments: Advertisements start : It’s the start value …
numpy.arange() : Create a Numpy Array of evenly spaced numbers in PythonRead More
Python: Search strings in a file and get line numbers of lines containing the string
In this article, we are going to discuss, how to search for single or multiple strings in a file and get all the matched lines along with their line numbers. Check if a string exists in a file To check if a given string exists in the file or not, we have created a function, …
Python: Search strings in a file and get line numbers of lines containing the stringRead More
Python: Remove all numbers from string
In this article we will discuss different ways to remove characters except digits from string in Python. Remove all numbers from string using regex Python’s regex module provides a function sub() i.e. Advertisements re.sub(pattern, repl, string, count=0, flags=0) It returns a new string. This new string is obtained by replacing all the occurrences of the …
Javascript: Check if a string contains numbers
There is a general requirement while developing with javascript to check if a string contains numbers. This article will discuss checking if a string contains numbers in a javascript string using different methods and example illustrations.We will be creating custom functions to check if a given string contains numbers and examples of their usage. Table …
Javascript: Remove all but numbers from string
This article will discuss removing all the non-numeric characters from a string in javascript using various methods and example illustrations. Table of Contents:- Remove all non-numeric characters from a string in javascript Remove all non-numeric characters from a string in javascript except decimal Remove all non-numeric characters from string in javascript Using replace() and Regular …
Create Pandas Dataframe with Random Numbers
In this article we will discuss how to create Dataframe of random integers or floats. Table Of Contents Create Dataframe with Random Integers using randint() Create DataFrame with one column of random numbers Create DataFrame with multiple columns of Random Numbers Create DataFrame of random numbers and convert values to string Create Pandas Dataframe with …
Extract Numbers from String in Python
In this article, we will learn to extract the numbers from a given string in Python. Table Of Contents What is a String in Python Extract numbers from string using isdigit() in List Comprehension : Extract numbers from string using re.findall() method Extract numbers from string using split() and append() methods : Extract numbers from …