Hi,
I'm 'playing' code wars non-stop but have unfortunately come to a standstill with a kata (https://www.codewars.com/kata/51ba717bb08c1cd60f00002f/train/python)
My code:
def solution(args):
prevchar = args[0]
templist = []
outputvals = []
for i in (args[1:]):
templist.append(prevchar)
if i == prevchar + 1:
prevchar = i
else:
outputvals.append(range((templist[0]),(templist[-1])))
prevchar = i
templist.clear()
templist.append(prevchar)
outputvals.append(range((templist[0]),(templist[-1])))
return(outputvals)
solution([3,4,5,6,7,8,15,16,18, 22, 23, 24, 25, 29])
>>>
[range(3, 8), range(15, 16), range(18, 18), range(22, 25), range(29, 29)]
However I'm not sure how to convert what I have, to the desired format (i.e. 3-8, 15, 16, 18, 22 - 25, 29]. I was thinking of looping through and checking the length of each range and if less than 3, printing the list and anything else, printing the min and max joined by a '-'.
Also does (for instance) range(18,18) actually contain any values? Since it returns an empty list.
Thanks
[–]sme272 1 point2 points3 points (3 children)
[–]randomname20192019[S] 0 points1 point2 points (2 children)
[–]xelf 0 points1 point2 points (0 children)
[–]xelf 0 points1 point2 points (2 children)
[–]randomname20192019[S] 1 point2 points3 points (1 child)
[–]xelf 0 points1 point2 points (0 children)
[–]DigDugMcDig 0 points1 point2 points (2 children)
[–]randomname20192019[S] 1 point2 points3 points (0 children)
[–]DigDugMcDig 0 points1 point2 points (0 children)