Merge the Tools! Python
Consider the following: 1. A string, s, of length where s=c0,c1.....cn-1. 2. An integer, k, where k is a factor of n. We can split s into n/k subsegments where each subsegment, ti, consists of a contiguous block of k characters in s. Then, use each ti to create string ui such that: 1. The characters in ui are a subsequence of the characters in ti. 2. Any repeat occurrence of a character is removed from the string such that each character in ui occu
View Solution →Introduction to Sets Python
A set is an unordered collection of elements without duplicate entries. When printed, iterated or converted into a sequence, its elements will appear in an arbitrary order. Example >>> print set() set([]) >>> print set('HackerRank') set(['a', 'c', 'e', 'H', 'k', 'n', 'r', 'R']) >>> print set([1,2,1,2,3,4,5,6,0,9,12,22,3]) set([0, 1, 2, 3, 4, 5, 6, 9, 12, 22]) >>> print set((1,2,3,4,5,5)) set([1, 2, 3, 4, 5]) >>> print set(set(['H','a','c','k','e','r','r','a','n','k'])) se
View Solution →Eye and Identity Python
identity The identity tool returns an identity array. An identity array is a square matrix with all the main diagonal elements as 1 and the rest as 0. The default type of elements is float. import numpy print numpy.identity(3) #3 is for dimension 3 X 3 #Output [[ 1. 0. 0.] [ 0. 1. 0.] [ 0. 0. 1.]] eye The eye tool returns a 2-D array with 1's as the diagonal and 0's elsewhere. The diagonal can be main, upper or lower depending on the optional parameter k. A positive
View Solution →Array Mathematics Python
Basic mathematical functions operate element-wise on arrays. They are available both as operator overloads and as functions in the NumPy module. import numpy a = numpy.array([1,2,3,4], float) b = numpy.array([5,6,7,8], float) print a + b #[ 6. 8. 10. 12.] print numpy.add(a, b) #[ 6. 8. 10. 12.] print a - b #[-4. -4. -4. -4.] print numpy.subtract(a, b) #[-4. -4. -4. -4.] print a * b #[ 5. 12.
View Solution →Polar Coordinates Python
Task: You are given a complex z. Your task is to convert it to polar coordinates. Input Format: A single line containing the complex number z. Note: complex() function can be used in python to convert the input as a complex number. Constraints: Given number is a valid complex number Output Format Output two lines: The first line should contain the value of r. The second line should contain the value of y.
View Solution →