Sequence Type and Iterables in Python

Sequence Type in python are strings, lists, tuples, byte sequences, byte arrays and range objects they are indexable and you can iterate through them. All the sequence type are iterables you can get each element one by one. But all iterables are not sequence type like for example set in which you can iterate through a set but you cannot use indexing. Lets take at some example using sequence type and … Continue reading Sequence Type and Iterables in Python

Finding n largest Element in Array Python

Let’s say we have a list [1,2,50,20,10,75,90] and the requirement here in the problem statement is to find the 3 largest element in the list which is 90,75,50, lets see how to solve it. In the above solution we have a findNLargest function which takes in an array and the number of elements we want to retrieve from the list, first we sort the array … Continue reading Finding n largest Element in Array Python

Isomorphic String Python

Two strings x and y are isomorphic if the characters in x can be replaced to get y. All occurrences of a character must be replaced with another character while preserving the order of characters. No two characters may map to the same character, but a character may map to itself. Input: s = “abc”, t = “def” Output: true Input: s = “foo”, t = “bar” Output: false Continue reading Isomorphic String Python

Mapping two Strings to form a Dictionary

Let’s see how we can map two strings into a dictionary with each character in one string forming the key and each character in the second string forming the value and the mapping is formed in sequence from left to right, considering the fact that both the strings are of equal length. Lets say we have two strings ‘abc’ and ‘def’ we want to create … Continue reading Mapping two Strings to form a Dictionary