Showing posts with label HackerRank-Functionals. Show all posts
Showing posts with label HackerRank-Functionals. Show all posts

HackerRank Python Solution - Functionals - Reduce Function

Given a list of rational numbers, find their product.

Concept:
  • The reduce() function applies a function of two arguments cumulatively on a list of objects in succession from left to right to reduce it to one value. Say you have a list, say [1,2,3] and you have to find its sum.
>>> reduce(lambda x, y : x + y,[1,2,3])
6

HackerRank Python Solution - Functionals - Validating Email Addresses with a Filter

  • You are given an integer N followed by N email addresses. Your task is to print a list containing only valid email addresses in lexicographical order.
  • Valid email addresses must follow these rules:
    • It must have the username@websitename.extension format type.
    • The username can only contain letters, digits, dashes and underscores [a-z],[A-Z],[0-9],[_-].
    • The website name can only have letters and digits [a-z],[A-Z],[0-9].
    • The extension can only contain letters [a-z],[A-Z].
    • The maximum length of the extension is 3.

HackerRank Python Solution - Functionals - Map and Lambda Function

Let's learn some new Python concepts! You have to generate a list of the first Fibonacci numbers, 0 being the first number. Then, apply the map function and a lambda expression to cube each Fibonacci number and print the list.

Concept:
  • The map() function applies a function to every member of an iterable and returns the result. It takes two parameters: first, the function that is to be applied, and second, the iterables.
  • Let's say you are given a list of names, and you have to print a list that contains the length of each name.
>> print (list(map(len, ['Tina', 'Raj', 'Tom'])))  
[4, 3, 3]  

You might also like

Deploy your Django web app to Azure Web App using App Service - F1 free plan

In this post, we will look at how we can deploy our Django app using the Microsoft Azure app service - a free plan. You need an Azure accoun...