Python Answers

Questions answered by Experts: 5 288

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Search

Rotate Words In Sentence

Given a sentence and an integer N, write a program to rotate letters of the sentence among the words without changing the length of those words and positions of the spaces.

Input

The first line of input will be a sentence.
The second line of input will be an integer N.

Output

The output should be a single line containing the sentence by rotating the letters among the words without changing the length of the words and positions of the spaces.

Explanation

For example, if the given sentence and N are

Welcome to your first problem
5

Rotate the sentence 5 letters towards right side without changing the length of the words and position of spaces in the original sentence.
So the output should be

oblemWe lc omet oyour firstpr
Sample Input 1
Welcome to your first problem
5
Sample Output 1
oblemWe lc omet oyour firstpr

Sample Input 2
All the best
2
Sample Output 2
stA llt hebe


Concatenate Word Pairs
Given a sentence and an integer L, write a program to concatenate word pairs so that the concatenated word has the length L.
Input
The first line of input will be a sentence.
The second line of input will be an integer L.
Output
The output should be containing the unique concatenated word pairs each in a line in the lexicographical order.
Explanation
For example, if the given sentence and L are
Welcome to your exam
6
The words which can be paired so that they make concatenated word with length 6 are
Word1	Word2
to	your
to	exam
exam	to
your	to
So the output should be printing each concatenated word in a line in the lexicographical order
examto
toexam
toyour
yourto
Sample Input 1
Welcome to your exam
6
Sample Output 1
examto
toexam
toyour
yourto

Sample Input 2
My parents and I went to a movie
9
Sample Output 2
Myparents
moviewent
parentsMy
parentsto
toparents
wentmovie
Balanced Brackets

You are given an expression string S which contains expressions that are made of bracket characters {, }, (, ), [, ]. Each expression in the string is separated by space.
Two brackets are considered to be a matched pair if an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [], {}, and ().
A matching pair of brackets is not balanced if the set of brackets it encloses are not matched. For example, 
{[(])} is not balanced because the contents in between { and } are not balanced. The pair of square brackets enclose a single, unbalanced opening bracket, (, and the pair of brackets enclose a single, unbalanced closing square bracket, ].
Write a program to examine whether each expression in 
S is balanced.
Input
The first line contains a string S with space-separated bracket expressions.
Sample Input 1
{()} ({}
Sample Output 1
YES
NO
Sample Input 2
{}[] [({})] {}
Sample Output 2
YES
YES
YES
Smaller Scores
A group of people(P) are playing an online game. Their scores are stored in the order of their entry time in S. Each integer S[i] corresponds to the score of the person Pi.
For each person 
Pi you have to report the number of people who played after the person and scored less than the person.
Input
The first line contains a single integer 
N. The second line contains N space-separated integers representing the score S[i] of person Pi.
Output
The output should contain 
N space-separated integers representing the number of people who played after the person and scored less than the person.
Explanation
Given 
S = 13 12 11
Score of P1 is 13. Score of P2 is 12. Score of P3 is 11.
The number of people who played after P1 and scored less than 13 is 2(12, 11). The number of people who played after P2 and scored less than 12 is 1(11). The number of people who played after P3 and scored less than 11 is 0.
The output is 
2 1 0.
Sample Input 1
3
13 12 11
Sample Output 1
2 1 0
Sample Input 2
4
4 3 5 2
Sample Output 2
2 1 1 0

 Explain language translation and text classification in NLP. Give examples. 


How do we extract information from a given sentence of words in NLP? Give some examples of information extraction.


 Explain information retrieval in detail. What is the use of vector space model in information retrieval?


 Explain parts of speech (POS) tagging. What are the advantages of POS tagging?


Define Uni-gram, bi-grams and N-grams in detail. What are N-grams useful for? Also explain hidden markov model in detail


Given a string, write a program to re-arrange all the numbers appearing in the string in decreasing order. Note: There will not be any negative numbers or numbers with decimal part


LATEST TUTORIALS
APPROVED BY CLIENTS