title-img


Zipped! python

zip([iterable, ...]) This function returns a list of tuples. The th tuple contains the th element from each of the argument sequences or iterables. If the argument sequences are of unequal lengths, then the returned list is truncated to the length of the shortest argument sequence. Sample Code >>> print zip([1,2,3,4,5,6],'Hacker') [(1, 'H'), (2, 'a'), (3, 'c'), (4, 'k'), (5, 'e'), (6, 'r')] >>> >>> print zip([1,2,3,4,5,6],[0,9,8,7,6,5,4,3,2,1]) [(1, 0), (2, 9), (3, 8), (4, 7), (

View Solution →

Input() python

input() In Python 2, the expression input() is equivalent to eval(raw _input(prompt)). Code >>> input() 1+2 3 >>> company = 'HackerRank' >>> website = 'www.hackerrank.com' >>> input() 'The company name: '+company+' and website: '+website 'The company name: HackerRank and website: www.hackerrank.com' Task You are given a polynomial P of a single indeterminate (or variable), x. You are also given the values of x and k. Your task is to verify if P(x) = k. Constraints

View Solution →

Python Evaluation

The eval() expression is a very powerful built-in function of Python. It helps in evaluating an expression. The expression can be a Python statement, or a code object. For example: >>> eval("9 + 5") 14 >>> x = 2 >>> eval("x + 3") 5 Here, eval() can also be used to work with Python keywords or defined functions and variables. These would normally be stored as strings. For example: >>> type(eval("len")) <type 'builtin_function_or_method'> Without eval() >>> type("len") <type

View Solution →

Athlete Sort python

You are given a spreadsheet that contains a list of N athletes and their details (such as age, height, weight and so on). You are required to sort the data based on the Kth attribute and print the final resulting table. Follow the example given below for better understanding. image Note that K is indexed from 0 to M-1, where M is the number of attributes. Note: If two attributes are the same for different rows, for example, if two atheletes are of the same age, print the row that appear

View Solution →

Any or All python

any() This expression returns True if any element of the iterable is true. If the iterable is empty, it will return False. Code >>> any([1>0,1==0,1<0]) True >>> any([1<0,2<1,3<2]) False all() This expression returns True if all of the elements of the iterable are true. If the iterable is empty, it will return True. Code >>> all(['a'<'b','b'<'c']) True >>> all(['a'<'b','c'<'b']) False Task You are given a space separated list of integers. If all the integers are posi

View Solution →