Python Text Wrapping and Filling

George John
Updated on 30-Jul-2019 22:30:23

4K+ Views

In python the textwrap module is used to format and wrap plain texts. There are some options to format the texts by adjusting the line breaks in the input paragraph. To use these modules, we need to import the textwrap module in our code. import textwrap The Textwrapper instance attributes of the constructors are as follows − Sr.No. Attribute & Description 1 width The maximum length of lines. Default value is 70 2 expand_tabs If the value of this attribute is true, then all tabs will be replaced by spaces. Default value ... Read More

Chaining comparison operators in C#

Chandu yadav
Updated on 30-Jul-2019 22:30:23

370 Views

C# has many operators that work on the left-right and righ-left associativity. Chanining depends on the left-to-right associativity on operators with same precedence. Operator precedence determines the grouping of terms in an expression. This affects evaluation of an expression. Certain operators have higher precedence than others do; for example, the multiplication operator has higher precedence than the addition operator. The operators with the highest precedence appear at the top of the table, those with the lowest appear at the bottom. Within an expression, higher precedence operators are evaluated first. To check whether a string is null or not, you can ... Read More

Python program to count unset bits in a range.

Ankith Reddy
Updated on 30-Jul-2019 22:30:23

145 Views

Given a positive a number and the range of the bits. Our task is to count unset bits in a range. Input : n = 50, starting address = 2, ending address = 5 Output : 2 There are '2' unset bits in the range 2 to 5. Algorithm Step 1 : convert n into its binary using bin(). Step 2 : remove first two characters. Step 3 : reverse string. Step 4 : count all unset bit '0' starting from index l-1 to r, where r is exclusive. Example Code # ... Read More

Python Unicode Database

Arjun Thakur
Updated on 30-Jul-2019 22:30:23

312 Views

The unicodedata module is used to access all of the Unicode characters using Unicode character databases. In this database, there are character properties of all characters. To use this modules, we need to import the unicodedata module in our code. import unicodedata Unicode Database Methods Some modules of the unicodedata module are described here. Module (unicodedata.lookup(name)) − This method is used to lookup the characters by name. When the name is valid, it should return the character. Otherwise it will raise the KeyError. Module (unicodedata.name(chr[, default]))− This method is used to return the name of the given ... Read More

Python program to find Union of two or more Lists?

Samual Sam
Updated on 30-Jul-2019 22:30:23

473 Views

Union operation means, we have to take all the elements from List1 and List 2 and all the elements store in another third list. List1::[1, 2, 3] List2::[4, 5, 6] List3::[1, 2, 3, 4, 5, 6] Algorithm Step 1: Input two lists. Step 2: for union operation we just use + operator. Example code # UNION OPERATION A=list() B=list() n=int(input("Enter the size of the List ::")) print("Enter the Element of first list::") for i in range(int(n)): k=int(input("")) A.append(k) print("Enter the Element of second list::") for i in range(int(n)): ... Read More

Python Internet String Preparation

Ankith Reddy
Updated on 30-Jul-2019 22:30:23

226 Views

To identify different things in the internet, it is necessary to compare different identification for equality. The comparison procedure depends on the application domain. For an example, some things are case-insensitive etc. To check these kind of information stringprep is used. The RFC 3454 defines the procedure to prepare the Unicode strings before transmitting through the wire. After going through the preparation procedure, they have a certain normalized form. The RFC defines a set of tables; these tables can be combined into profiles. For an example there is a profile of stringprep is nameprep. In the nameprep, there are internationalized ... Read More

Python program to find Intersection of two lists?

karthikeya Boyini
Updated on 30-Jul-2019 22:30:23

403 Views

Intersection operation means, we have to take all the common elements from List1 and List 2 and all the elements store in another third list. List1::[1, 2, 3] List2::[2, 3, 6] List3::[2, 3] Algorithm Step 1: input lists. Step 2: first traverse all the elements in the first list and check with the elements in the second list. Step 3: if the elements are matched then store in third list. Example code #Intersection of two lists def intertwolist(A, B): C = [i for i in A if i in B] ... Read More

Python GNU readline Interface

Chandu yadav
Updated on 30-Jul-2019 22:30:23

593 Views

The readline is UNIX specific module. It defines a number of functions to read and write history files in easier way from python interpreter. We can use this module directly or using the rlcompleter module. This module settings may affect the built-in input() method prompt and also the interactive prompt. For the MAC based system (on MAC OS X) this readline module can be implemented using the libedit library. The libedit configuration is different from GNU readline. To use this module, we need to import the readline module in the python code import readline Some methods of ... Read More

Check if a File is hidden in C#

Ankith Reddy
Updated on 30-Jul-2019 22:30:23

601 Views

To retrieve the attributes of a file, use the FileAttributes Eumeration. It has various members like compressed, directory, hidden, etc. To check if a file is hidden, use the hidden member name. If the FileAttributes.hidden is set that would mean the file is hidden. Firstly, get the path to find the attributes. FileAttributes attributes = File.GetAttributes(path); If the following is set, that would mean the file is now hidden using the hidden member name. File.SetAttributes(path, File.GetAttributes(path) | FileAttributes.Hidden); Console.WriteLine("The {0} file is hidden.", path);

Second most repeated word in a sequence in Python?

karthikeya Boyini
Updated on 30-Jul-2019 22:30:23

624 Views

The string is given, our task is to find out the second repeated word. Here we Counter(iterator) for creating dictionary which contains word as key and its frequency as value. Algorithm Step 1: Create user define list. Step 2: Then convert list into a dictionary. Step 2: Next get the values and sort them in descending order. Step 3: Then the second element is the second largest value. Step 4: Next again traverse whole dictionary and display key whose value is equal to second largest element. Example code # To print Second most repeated word in a ... Read More

Advertisements