Tag: Line
C++ : How to Initialize a map in one line using initialzer_list ?
In this article we will discuss how to initialize a map with std::initialzer_list<T>. Let’s create a map of string as key and int as value and initialize it with initializer_list i.e. Advertisements // Initialize a Map of string & int using initializer_list std::map<std::string, int> mapOfMarks = { {“Riti”,2}, {“Jack”,4} }; Here compiler will create following …
C++ : How to Initialize a map in one line using initialzer_list ?Read More
C++ : How to read a file line by line into a vector ?
In this article we will discuss how to read a file line by line and put them in a vector or perform some other operation each line. Reading File line by line First open the file i.e. Advertisements // Open the File std::ifstream in(“file.txt”); Now keep reading next line using getline() and push it in …
C++ : How to read a file line by line into a vector ?Read More
Read a file line by line in Python (5 Ways)
In this article we will discuss different ways to read a file line by line in Python. Suppose we have a file data.txt in same directory as our python script. Let’s see how to read it’s contents line by line. Solution for Small Files : Get list of all lines in file using readlines() First …
How to create multi line string objects in python ?
In this article we will discuss different ways to create long multi line string in python. Using triple quotes to create string of multiple lines We can wrap the multi line string in triple quotes i.e. either <> and assign it to a string variable. It will be stored in same multi line format. Checkout …
How to create multi line string objects in python ?Read More
Python: Print items of a dictionary line by line (4 Ways)
In this article, we will discuss different ways to print line by line the contents of a dictionary or a nested dictionary in python. Subscribe Table Of Contents Print a dictionary line by line using for loop & dict.items() Print a dictionary line by line by iterating over keys Print a dictionary line by line …
Python: Print items of a dictionary line by line (4 Ways)Read 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: Read a CSV file line by line with or without header
In this article we will discuss how to read a CSV file line by line with or without header. Also select specific columns while iterating over a CSV file line by line. Suppose we have a csv file students.csv and its contents are, Advertisements Id,Name,Course,City,Session 21,Mark,Python,London,Morning 22,John,Python,Tokyo,Evening 23,Sam,Python,Paris,Morning 32,Shaun,Java,Tokyo,Morning We want to read all the …
Python: Read a CSV file line by line with or without headerRead More
Python: Read a file in reverse order line by line
In this article we will discuss an efficient solution to read the contents of a text or CSV file in reverse order i.e. either line by line or get them as a reversed list. Read a file line by line in reversed order using python An efficient solution to read a file in reverse order …
Python: if-else in one line – ( A Ternary operator )
In this article, we will learn how to use if-else in one line in python. Other programming languages like C++ and Java have ternary operators, which are useful to make decision making in a single line. Python does not have a ternary operator. But in python, we can use the if-else in a single line, …
Python: if-else in one line – ( A Ternary operator )Read More
Matplotlib – Line Plot explained with examples
In Python, the pyplot library of the Matplotlib module helps in achieving data visualization through easy ways. We can create different graphs, but in this article, we will be discussing the Line graph. We will be using the ‘plot’ method to view our data in a graphical representation. pyplot.plot() syntax Let us look at the …