0
def swap(s1,s2):
    if len(s1) > len(s2):
        s1, s2 = s2, s1
        return (s1, s2)

str1 = "cheese"
str2 = "spoon"

str3, str4 = swap(str1, str2)

print ("%s, %s : %s, %s" % (str1, str2, str3, str4))

I noticed from Levenshtein Distance code that an easy way to swap over variables is

s1, s2 = s2, s1

but to unpack from the function we use

str3, str4 = ...

To me they look like the same thing, but I know they're not. Can someone clarify the use of the comma in these cases?

Community
  • 1
  • 1
Mr Mystery Guest
  • 1,378
  • 15
  • 45

0 Answers0