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

  • string modifying methods

    Method
    Description
    Examples
    Results
    replace('a', 'b')
    Replaces all the occurrences of a with b
    'Abcde'.replace('A', 'B') 'ABBA'.replace('A', 'B') 'ABBA'.replace('AB', 'C')
    Bbcde BBBB CBA
    strip()
    Removes whitespace from both ends
    ' Hi Bob '.strip()
    Hi Bob
    lstrip()
    Removes whitespace from the beginning
    ' Hi Bob '.lstrip()
    Hi Bob
    rstrip()
    Removes whitespace from the end
    ' Hi Bob '.rstrip()
    Hi Bob
    removeprefix('a')
    Removes the specified prefix if it’s present
    'Hi Bob!'.removeprefix('Hi') 'Hi Bob!'.removeprefix('hi')
    Bob! Hi Bob!
    removesuffix('a')
    Removes the specified suffix if it’s present
    'Hi Bob!'.removesuffix('!') 'Hi Bob?'.removesuffix('!')
    Hi Bob Hi Bob?
    The methods replace and strip are very popular and are used pretty often in real-life programs.

    Challenge

    Each gene's code uses the four nucleotide bases of DNA: adenine (A), cytosine (C), guanine (G), and thymine (T). We don’t like abbreviations, so we would like to expand these abstractions any time we find those in the text. Given a text with abstractions including A, C, G, and T, expand those into their actual names.
    The input contains a single line with text with abbreviations.
    The program should print the same text with expanded abstractions in the output.
    Input
    Output
    Each gene's code uses the four nucleotide bases of dna: A, C, G, and T
    Each gene's code uses the four nucleotide bases of dna: adenine, cytosine, guanine, and thymine
     
    To check your solution you need to sign in
    Sign in to continue