Solitare Solution:(did this in a leetcode style problem)
cards = input()class Solution: def solitare(cards): newlist = cards.split(", ") ret = "" newlist.pop(0) for i in range(0, len(newlist)-1): if newlist[len(newlist)-1][0] == newlist[len(newlist)-2][0] or newlist[len(newlist)-1][1] == newlist[len(newlist)-2][1]: newlist.pop(0) for i in range(0, len(newlist)-1): ret += newlist[i] + ", " ret += newlist[len(newlist)-1] return retprint(Solution.solitare(cards))
Solitare Solution: (did this in a leetcode style problem)
cards = input() class Solution: def solitare(cards): newlist = cards.split(", ") ret = "" newlist.pop(0) for i in range(0, len(newlist)-1): if newlist[len(newlist)-1][0] == newlist[len(newlist)-2][0] or newlist[len(newlist)-1][1] == newlist[len(newlist)-2][1]: newlist.pop(0) for i in range(0, len(newlist)-1): ret += newlist[i] + ", " ret += newlist[len(newlist)-1] return ret print(Solution.solitare(cards))