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

Rearrange Numbers in String

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.

Input

The input will be a single line containing a string.

Output

The output should be a single line containing the modified string with all the numbers in string re-ordered in decreasing order.

Explanation

For example, if the given string is "I am 5 years and 11 months old", the numbers are 5, 11. Your code should print the sentence after re-ordering the numbers as "I am 11 years and 5 months old".

Sample Input

I am 5 years and 11 months old

Sample Output

I am 11 years and 5 months old




You are given a square matrix A of dimensions NxN. You need to apply the below given 3 operations on the matrix A.


Given a sentence as input, find all the unique combinations of two words and print the word combinations that are not adjacent in the original sentence in lexicographical order

For example, if the given sentence is "python is a programming language", the possible unique combination of two are (a, is), (a, language), (a, programming), (a, python), (is, language), (is, programming), (is, python), (language, programming), (language, python), (programming, python). Out of these the combinations, (a, is), (a, programming), (is, python), (language, programming) are not valid as they contain words that are adjacent in the given sentence. So the output should be

a language

a python

is language

is programming

language python

programming python

input: input:

raju always plays cricket to be or not be

output: output:

always cricket be be

cricket raju be not

plays raju or to

to to

it should satisfy both inputs and hidden testcases?

so,can anyone make code for this?


Given a range represented by two positive integers L and R. Find the number lying in the range having the maximum product of the digits. (Inclusive of L and R).

For example, if the given T is 2, read the L and R of the first test case in the next line. If the given L and R are 1 and 10 respectively. As 9 is the maximum product of digits, so the output for the first test case is 9.

If the L and R are 15 to 30 respectively. The product of the digits of number 29 is 18. As 18 is the maximum product in the range, so the output should be 18.

input:

2 1

1 10

15 30

output:

9

29


Given a matrix of order M*N and a value K, write a program to rotate each ring of the matrix clockwise by K elements. If in any ring has less than or equal to K elements, then don’t rotate that ring

For example, if the given M and N are 4 and 4 respectively. If the matrix elements are

1 2 3 4

5 6 7 8

9 10 11 12

13 14 15 16

If the given K is 3. Rotate each ring of the matrix by 3 elements.

In the above matrix, the elements (1, 2, 3, 4, 8, 12, 16, 15, 14, 13, 9, 5) is a ring, similarly, the elements (6, 7, 11, 10) will make a ring.

Therefore, by rotating each ring in clockwise direction by 3 elements will give (13, 9, 5, 1, 2, 3, 4, 8, 12, 16, 15, 14) and (10, 6, 7, 11). So the output should be

13 9 5 1

14 7 11 2

15 6 10 3

16 12 8 4

input:4 4

1 2 3 4

5 6 7 8

9 10 11 12

13 14 15 16

3

output:

13 9 5 1

14 7 11 2

15 6 10 3

16 12 8 4 there should be no space before starting index line by line


Given an array n integers, find and print all the unique triplets (a, b, c) in the array which give the sum K. (a+b+c=K).

The first line of the input will be space separated integers, denoting the elements of the array. The second line of the input will be an integer denoting the required sum KOutput


The output should be multiple lines, each line containing a unique triplet. The elements of the triple must be sorted in increasing order and all the triplets printed must be sorted in increasing order. Print "No Matching Triplets Found" if there are no triplets with the given sum.

input: 0 12 17 8 9 21

22

ouput:(0, 8, 21)

(0, 12, 17)

(8, 9, 12) should be like this


Given a matrix of order M*N and a value K, write a program to rotate each ring of the matrix clockwise by K elements. If in any ring has less than or equal to K elements, then don’t rotate that ring.

For example, if the given M and N are 4 and 4 respectively. If the matrix elements are

1 2 3 4

5 6 7 8

9 10 11 12

13 14 15 16

If the given K is 3. Rotate each ring of the matrix by 3 elements.

In the above matrix, the elements (1, 2, 3, 4, 8, 12, 16, 15, 14, 13, 9, 5) is a ring, similarly, the elements (6, 7, 11, 10) will make a ring.

Therefore, by rotating each ring in clockwise direction by 3 elements will give (13, 9, 5, 1, 2, 3, 4, 8, 12, 16, 15, 14) and (10, 6, 7, 11). So the output should be

13 9 5 1

14 7 11 2

15 6 10 3

16 12 8 4


The first line of the input will contain a string A.

The second line of the input will contain a string B.Output


The output should contain overlapping word if present else print "No overlapping".Explanation


For example, if the given two strings, A and B, are "ramisgood" "goodforall"

The output should be "good" as good overlaps as a suffix of the first string and prefix of next.

for input

correct

wrong


No overlapping

The first line contains a single integer N.

Next N lines contain N space-separated integers Aij (i - index of the row, j - index of the column).

Next lines contain various operations on the array. Each operation on each line (Beginning either with R, U or Q).

-1 will represent the end of input.

sample input

2

5 6

7 8

R 90

Q 0 1

R 270

Q 1 1

R 180

U 0 0 4

Q 0 0

-1

Same output

5
8
8






Write a python program to display your details like name,age,address in three different lines.


LATEST TUTORIALS
APPROVED BY CLIENTS