I. Reversing a string in Python ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PYTHON a = "codementor" print "Reverse is", a[::-1] PERL my $a ="GeeksForGeeks" say 'Reverse is '. reverse $a; -------------------------------------------------------------------------- II. Transposing a Matrix ^^^^^^^^^^^^^^^^^^^^^^^^ PYTHON mat = [[1, 2, 3], [4, 5, 6]] zip(*mat) PERL use List::MoreUtils qw/each_arrayref/; my @l = ([1, 2, 3], [4, 5, 6]); my @a; my $iter = each_arrayref(@l); while (my @t = $iter->()) { push @a, \@t; } -------------------------------------------------------------------------- III. Store all three values of the list in 3 new variables ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PYTHON a = [1, 2, 3] x, y, z = a PERL my @a = qw/1 2 3/; my ($x, $y, $z) = @a; -------------------------------------------------------------------------- IV. Create a single string from all the elements in list below ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PYTHON a = ["Code", "mentor", "Python", "Developer"] print " ".join(a) PERL my @a = qw/Code mentor Python Developer/; say "@a"; -------------------------------------------------------------------------- V. Write a Python code to print ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PYTHON list1 = ['a', 'b', 'c', 'd'] list2 = ['p', 'q', 'r', 's'] for x, y in zip(list1,list2): print x, y PERL my @list1 = qw/a b c d/; my @list2 = qw/p q r s/; for (my $i=0; $i<@list1; ++$i) { say "$list[$i] $list2[$i]"; } -------------------------------------------------------------------------- VI. Swap two numbers with one line of code ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PYTHON a = 7 b = 5 b, a = a, b PERL my ($a, $b) = (7, 5); ($b, $a) = ($a, $b); -------------------------------------------------------------------------- VII. Print "codecodecodecode mentormentormentormentormentor" without using loops ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PYTHON print "code" * 4 + ' ' + "mentor" * 5 PERL say 'code' x 4, ' ', 'mentor' x 5; -------------------------------------------------------------------------- VIII. Convert it to a single list without using any loops ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PYTHON import itertools a = [[1, 2], [3, 4], [5, 6]] list(itertools.chain.from_iterable(a)) PERL my @a = ([1, 2], [3, 4], [5, 6]); @l = map { @$_ } @a; -------------------------------------------------------------------------- IX. Checking if two words are anagrams ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PYTHON from collections import Counter def is_anagram(str1, str2): return Counter(str1) == Counter(str2) PERL sub is_anagram { return (join('', sort split('', $_[0])) eq join('', sort split('', $_[1]))) ? 'True' : 'False'; } -------------------------------------------------------------------------- X. Taking a string input ^^^^^^^^^^^^^^^^^^^^^^^^ For example "1 2 3 4" and return [1, 2, 3, 4] Remember list being returned has integers in it. Don't use more than one line of code. PYTHON result = map(lambda x:int(x) ,raw_input().split()) PERL my @r = split /\s+/, ;