fb pixel

Introduction to Python

  • Profound Academy

    • Status
      • 1
        Input and Output
      • 2
        Variables and Integer Arithmetic
      • 3
        Conditional Operators
      • 4
        Advanced Conditions - Nesting
      • 5
        Types and Variables
      • 6
        Strings
      • 7
        Lists
      • 8
        For Loops
      • 9
        While Loops
      • 10
        continue, break, while...else
      • 11
        String and List methods
      • 12
        Nested Loops
      • 13
        List Comprehension
      • 14
        Tuples and Sets
      • 15
        dict
      • 16
        Functions
      • 17
        Functions 2
      • 18
        Lambda and higher-order functions
      • 19
        Files

  • set comprehension

    Much like list comprehension, set comprehension also allows to create a set with a single line of code. The only difference is the use of curly brackets {} instead of [].
    s = set()
    for i in range(10):
    	s.add(i**3)
    print(s)
    s = {i**3 for i in range(10)}
    print(s)
    Both of the programs will print exactly the same output: {0, 1, 64, 512, 8, 343, 216, 729, 27, 125}.

    Challenge

    Given n words, you are asked to print all the unique last letters of those words in increasing order. To sort the set/list you can use the sorted() function.
    The input contains a single line of space-separated words.
    The program should print a single line of space-separated unique letters in increasing order.
    Input
    Output
    abc def ghi
    c f i
    hello, how are you doing?
    , ? e u w
    Can you solve this in a single line 😎?
     
    To check your solution you need to sign in
    Sign in to continue