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

  • join()

    If split() divides the string into elements, join() unites list elements together and creates a string from them:
    l = ['Hi', 'I', 'am', 'Python', '3', '10']
    print('.'.join(l))    # Hi.I.am.Python.3.10
    print(' '.join(l))    # Hi I am Python 3 10
    print('*-*'.join(l))  # Hi*-*I*-*am*-*Python*-*3*-*10
    print('\n'.join(l))   # Hi
                          # I
                          # am
                          # Python
                          # 3
                          # 10

    Challenge

    Given 5 names in the input, print them separated by a -->.
    The input contains 5 names each on a separate line.
    The output should contain a single line - all 5 names separated by -->.
    Input
    Output
    Anna Simon Lily Bob David
    Anna-->Simon-->Lily-->Bob-->David
     
    To check your solution you need to sign in
    Sign in to continue