"Elementary" One-liners Overview
As you may know we have a special island for our coding newbies -- "Elementary". On this island we've created very simple missions which include hints to help solve them. So if you just have finished the TreeHouse or CodeAcademy courses, or you already know some python syntax, then this island is absolutely for you.
But our more advanced players are having fun there too. For example, they are adding an extra challenge and writing 'one-liners'. A one-liner is a program which takes just one line of code. For this weekly overview we will look at some of the interesting one-liners from our players.
I think you all know about "Fizz Buzz" game by now, it's often used to teach children division.
checkio=lambda n:("Fizz "*(1-n%3)+"Buzz "*(1-n%5))[:-1]or str(n)
Find the N-th power of the element in the array with the index N.
index_power=lambda a,n:-(len(a)<=n)or a[n]**n
Take the sum of the elements with even indexes, then multiply this summed number and the final element of the array.
checkio=lambda x: sum(x[::2])*x[-1] if x else 0
You are given text and a set of words. Find how many of the listed words are in the given text.
count_words = lambda t, w: len(list(filter(t.lower().count, w)))
Gather all of the capital letters in one word together in the order that they appear in the text.
find_message = lambda text: ''.join(filter(str.isupper, text))
Check if the string contains three words (words contains only letters) in succession.
checkio=lambda x:"www" in "".join('w' if w.isalpha() else 'd' for w in x.split())
Find the difference between the maximum and minimum element from a number array.
checkio = lambda *args: max(args) - min(args) if args else 0
In this mission you should implement some boolean operations: conjunction, disjunction, implication, exclusive and equivalence.
Just replace all the "right" words with the "left" and join them with commas.
left_join=lambda phrases: ''.join(list(''.join([i+',' for i in phrases]))[0:-1]).replace('right','left')
You are given a positive integer. Your function should calculate the product of the digits excluding all the zeros.
checkio = lambda n: eval("*".join(i for i in str(n) if i != '0'))
To be continued...
This is only first half. In the next article we will take look at the second set of missions I dug up from the Elementary Island.
Welcome to CheckiO - games for coders where you can improve your codings skills.
The main idea behind these games is to give you the opportunity to learn by exchanging experience with the rest of the community. Every day we are trying to find interesting solutions for you to help you become a better coder.Join the Game