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

  • Comparing sets

    Video preview
    Python allows to check if a set is a subset of another set. Set A is a subset of B if B contains all the elements of A and has some other elements as well. This can be done through a standard comparison operator:
    a = {1, 3, 5, 7, 18}
    b = {1, 7, 18}
    if b <= a:
    	print('B is a subset of A')
    elif a <= b:
    	print('A is a subset of B')
    else:
    	print('Not a subset!')
    This will print B is a subset of A. A contains all the elements of B (1, 7, 18) and has some additional ones as well (3, 5).
    To find the whole list of possible operations with Python sets visit their official page but these are the main operations that we will be focusing on.

    Challenge

    Given two lines of text, you are asked if those two lines contain the same set of symbols.
    The input contains 2 lines of text.
    The program should print Yes if they contain the same set of symbols and No otherwise.
    Input
    Output
    abcde edcbaaa
    Yes
    abcde edc
    Output No
     
    To check your solution you need to sign in
    Sign in to continue