code: def parse(version):
      """
      Parse the given version string and return either a :class:`Version` object
      or a :class:`LegacyVersion` object depending on if the given version is
      a valid PEP 440 version or a legacy version.
      """
      try:
          return Version(version)
      except InvalidVersion:
          return LegacyVersion(version)
  
imports: import collections
  import itertools
  import re
label_desc: Use image node_id 1 for calling a global function with example usage: parse(version) and returns: Version, LegacyVersion