Re: some problems for an introductory python test
Am 11.08.2021 um 05:22 schrieb Terry Reedy: Python is a little looser about whitespace than one might expect from reading 'normal' code when the result is unambiguous in that it cannot really mean anything other than what it does. Two other examples: >>> if3: print('yes!') yes! >>> [0] [0] 0 Not sure what you mean here - is it a joke? The first looks like an if statement, but isn't. The missing space *does* make a difference. (Try "if0" instead.) The second is normal indexing, which allows white space. I wouldn't consider that surprising, but maybe I should? (Honest question, I really don't know.) -- Wolfram Hinderer -- https://mail.python.org/mailman/listinfo/python-list
Re: count consecutive elements
Am 13.01.2021 um 22:20 schrieb Bischoop: I want to to display a number or an alphabet which appears mostly consecutive in a given string or numbers or both Examples s= ' aabskaaabad' output: c # c appears 4 consecutive times 8bbakebaoa output: b #b appears 2 consecutive times You can let itertools.groupy find the groups. max((len(tuple(group)), key) for key, group in itertools.groupby(s)) # (4, 'c') -- https://mail.python.org/mailman/listinfo/python-list
Re: best way to remove leading zeros from a tuple like string
Am 21.05.2018 um 01:16 schrieb bruceg113...@gmail.com: If I decide I need the parentheses, this works. "(" + ",".join([str(int(i)) for i in s[1:-1].split(",")]) + ")" '(128,20,8,255,-1203,1,0,-123)' Thanks, Bruce Creating the tuple seems to be even simpler. >>> str(tuple(map(int, s[1:-1].split("," '(128, 20, 8, 255, -1203, 1, 0, -123)' Wolfram -- https://mail.python.org/mailman/listinfo/python-list