python - Super Anagram Solution AOK? -
so i'm quite new python , trying create programme identify 'super anagrams' i.e anagrams have same first , lastly letters. came this, , works, i've got feeling there's cleaner way it. ideas? cheers.
words = input('enter words: ') listed = words.split() first = listed[0] sec = listed[1] first_split = (list(first)) second_split = (list(second)) if first_split[0]==second_split[0] , first_split[-1]==second_split[-1]: first_split_alpha = sorted(first_split) second_split_alpha = sorted(second_split) if first_split_alpha == second_split_alpha: print('super anagram!') else: print('huh?') else: print('huh?')
1) temporary variable listed
unnecessary. utilize tuple unpacking values
2) utilize of list
unnecessary. str
iterable object, too.
3) utilize of _alpha
unecessary. utilize sorted(foo)
in expression.
a,b = input('enter words: ').split() if sorted(a) == sorted(b) , a[0] == b[0] , a[-1] == b[-1]: print('super anagram!') else: print('huh?')
python super anagram
No comments:
Post a Comment