Created
November 22, 2017 09:36
-
-
Save jerinisready/e7e71f82c2f29eb2f424d2e131115c22 to your computer and use it in GitHub Desktop.
Someone Like This Puzzle in One Line
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
QUESTION | |
Let 'a' be the list of users who likes a post! I want to get displayed as below | |
eg 1 :- a = [] | |
Output : Nobody likes This | |
eg 2 :- a = ['Alice'] | |
Output : Alice likes This | |
eg 3 :- a = ['Alice','Bob'] | |
Output : Alice and Bob likes This | |
eg 4 :- a = ['Alice', 'Bob', 'Charls'] | |
Output : Alice, Bob and Charls likes This | |
eg 5 :- a = ['Alice', 'Bob', 'Charls','Denny'] | |
Output : Alice, Bob and 2 others likes This | |
eg 6 :- a = ['Alice', 'Bob', 'Charls','Denny','Emely'] | |
Output : Alice, Bob and 3 others likes This | |
""" | |
# a = [] | |
# a = ['Alice'] | |
# a = ['Alice', 'Bob'] | |
# a = ['Alice', 'Bob', 'Charls'] | |
# a = ['Alice', 'Bob', 'Charls','Denny'] | |
# a = ['Alice', 'Bob', 'Charls','Denny','Emely'] | |
print "%s likes this" % "%s, %s and %s" % (a[0],a[1],"%d others" % (len(a)-2) if len(a) > 3 else a[2]) if len(a) > 2 else "%s and %s likes this"% (a[0],a[1]) if len(a)==2 else "%s likes this" % (a[0] if len(a)==1 else "Nobody") | |
""" | |
This is done by using ternary Condition set | |
output = "True" if (condition) else "False" | |
""" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment