Find Differing Character in Strings

AlgorithmAlgorithmBeginner
Practice Now

This tutorial is from open-source community. Access the source code

Introduction

In this Python challenge, we are required to find the single different character between two strings.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL algorithm(("`Algorithm`")) -.-> algorithm/BasicAlgorithmsGroup(["`Basic Algorithms`"]) python(("`Python`")) -.-> python/ControlFlowGroup(["`Control Flow`"]) python(("`Python`")) -.-> python/DataStructuresGroup(["`Data Structures`"]) python(("`Python`")) -.-> python/FunctionsGroup(["`Functions`"]) python(("`Python`")) -.-> python/ObjectOrientedProgrammingGroup(["`Object-Oriented Programming`"]) python(("`Python`")) -.-> python/ErrorandExceptionHandlingGroup(["`Error and Exception Handling`"]) algorithm/BasicAlgorithmsGroup -.-> algorithm/arrays_strings("`Arrays Strings`") python/ControlFlowGroup -.-> python/conditional_statements("`Conditional Statements`") python/ControlFlowGroup -.-> python/for_loops("`For Loops`") python/DataStructuresGroup -.-> python/lists("`Lists`") python/DataStructuresGroup -.-> python/tuples("`Tuples`") python/FunctionsGroup -.-> python/function_definition("`Function Definition`") python/ObjectOrientedProgrammingGroup -.-> python/classes_objects("`Classes and Objects`") python/ObjectOrientedProgrammingGroup -.-> python/encapsulation("`Encapsulation`") python/ErrorandExceptionHandlingGroup -.-> python/catching_exceptions("`Catching Exceptions`") python/ErrorandExceptionHandlingGroup -.-> python/raising_exceptions("`Raising Exceptions`") python/FunctionsGroup -.-> python/build_in_functions("`Build-in Functions`") subgraph Lab Skills algorithm/arrays_strings -.-> lab-268808{{"`Find Differing Character in Strings`"}} python/conditional_statements -.-> lab-268808{{"`Find Differing Character in Strings`"}} python/for_loops -.-> lab-268808{{"`Find Differing Character in Strings`"}} python/lists -.-> lab-268808{{"`Find Differing Character in Strings`"}} python/tuples -.-> lab-268808{{"`Find Differing Character in Strings`"}} python/function_definition -.-> lab-268808{{"`Find Differing Character in Strings`"}} python/classes_objects -.-> lab-268808{{"`Find Differing Character in Strings`"}} python/encapsulation -.-> lab-268808{{"`Find Differing Character in Strings`"}} python/catching_exceptions -.-> lab-268808{{"`Find Differing Character in Strings`"}} python/raising_exceptions -.-> lab-268808{{"`Find Differing Character in Strings`"}} python/build_in_functions -.-> lab-268808{{"`Find Differing Character in Strings`"}} end

Str Diff

Problem

Given two strings, we need to find the single different character between them. The strings are assumed to be ASCII and are in lowercase. We cannot assume that the inputs are valid, so we need to check for None. If the inputs are valid, we can assume that there is only a single different character between the two strings. We also need to ensure that the solution fits in memory.

Requirements

To solve this problem, we need to consider the following requirements:

  • The strings are ASCII.
  • The strings are in lowercase.
  • We need to check for None input.
  • There is only a single different character between the two strings.
  • The solution should fit in memory.

Example Usage

Here are some examples of how to use the function:

  • None input -> TypeError
  • 'ab', 'aab' -> 'a'
  • 'aab', 'ab' -> 'a'
  • 'abcd', 'abcde' -> 'e'
  • 'aaabbcdd', 'abdbacade' -> 'e'

Summary

In this Python challenge, we have learned how to find the single different character between two strings. We have considered the requirements and provided examples of how to use the function.

Other Algorithm Tutorials you may like