Second Most Repeated Word in a Sequence in Python

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

816 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

Python Completion Function for GNU Readline

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

423 Views

Unix readline module has tab completion mechanism. To get these features, we have to use rlcompleter module. It can be used in python’s interactive mode. To use this module, we should import it using − import rlcompleter There is a class called Completer class − Method Completer.complete(text, state) This method is used to return the tab completion output. If there is a ‘.’ in the text, then it will try to get all related members of that command. When there is no dot ‘.’ it will just complete the text. Example Code import rlcompleter import sys ... Read More

Python Basic Date and Time Types

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

7K+ Views

To manipulate dates and times in the python there is a module called datetime. There are two types of date and time objects. The types are naïve and the aware. In the naïve object, there is no enough information to unambiguously locate this object from other date-time objects. In this approach it uses Coordinate Universal Time (UTC). In the aware type objects there are different information regarding algorithmic and political time adjustments. This type of objects is used to represent some specific time moments. To use this module, we should import it using − import datetime There are ... Read More

Sorting Collection of String and StringBuffer in Java

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

865 Views

In order to sort in Java as we know we can use either Comparable or Comparator interfaces in which we could also define our custom logic to sort.One of the approach to sort is to add the entity in TreeSet or TreeMap which would sort the entries as internally they also uses the comparable interface. Now String class in Java internally implements comparable interface so whenever we add string to a tree set or map it uses comparable logic of string class and sort the input entry strings.But String buffer do not have the implementation of comparable interface so ... Read More

Python Container Data Types

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

2K+ Views

In the collections there are some container datatypes, which are alternatives to python’s general purpose built-in containers like dict, list, set etc.Some of the containers are −Sr.No.Container & Description1namedtuple()Used to create tuple subclass with the name field2dequeQueue using list type data3CounterSubclass of dict to count the hash-table objects4ChainMapUsed to create single view of multiple mappings5OrderedDictSubclass of dict, where data are added in ordered manner6UserListWrapper for list to easier access.To use this module, we should import it using −import collectionsDeque ObjectThe Deque is basically a generalization of stack and queue structure, where it is initialized from left to right. It uses ... Read More

Extract Email ID from URL Text File in Python

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

336 Views

Here we are using regular expression package for extracting email-id from the URL-text file. Given the URL- text file. Using regular expression package we define the pattern of email-id then use findall() function, using this method to check the text which will match with this pattern. Input text= Please contact us at contact@tutorialspoint.com for further information."+\ " You can also give feedback at feedback@tutorialspoint.com" Output ['contact@tutorialspoint.com ', 'feedback@tutorialspoint.com'] Example code import re my_text = "Please contact us at contact@tutorialspoint.com for further information."+\ " You can also give feedback at feedback@tutorialspoint.com" my_emails = re.findall(r"[a-z0-9\.\-+_]+@[a-z0-9\.\-+_]+\.[a-z]+", ... Read More

Filter and Validate IP Constant in PHP

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

780 Views

The FILTER_VALIDATE_IP constant validates an IP address. Flags FILTER_FLAG_IPV4 − The value must be a valid IPv4 address FILTER_FLAG_IPV6 − The value must be a valid IPv6 address FILTER_FLAG_NO_PRIV_RANGE − The value must not be within a private range FILTER_FLAG_NO_RES_RANGE − The value must not be within a reserved range Return The FILTER_VALIDATE_IP constant does not return anything. Example Live Demo The following is the output. Invalid IP address! Let us see another example. Live Demo Here is the output. Valid IP address!

Char vs String Keywords in C#

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

1K+ Views

string keyword Use the string keyword to declare a string variable. The string keyword is an alias for the System.String class. For example. string name; name = "Tom Hanks"; Another example. string [] array={ "Hello", "From", "Tutorials", "Point" }; char keyword The char keyword is used to set array of characters. For example. char[] ch = new char[2]; ch[0] = 'A'; // Character literal ch[1] = 'B'; // Character literal Another example. char []letters= { 'H', 'e', 'l', 'l','o' };

Print Powers Using Anonymous Function in Python

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

316 Views

Here we used anonymous (lambda) function inside the map() built-in function. In Python, anonymous function is defined without name, its defined using lambda keyword. Algorithm Step 1: input n Step 2: input p Step 3: use anonymous function. Step 4: display result. Example Code # To display the powers of any number using anonymous function n = int(input("Enter how many terms want to display??")) p = int(input("Enter the number want to calculate power ::")) # use anonymous function cal = list(map(lambda i: p ** i, range(n))) # display the result print("The total terms is ::>", ... Read More

What to Study for a Career in Robotics

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

122 Views

To study robotics, you must have a degree in engineering. To make a career in this profession, you should acquire the knowledge of the related fields like electronics, mechanics, and computer science.

Advertisements