I have a string with digits like so – digit = “7316717” Now I want to split the string in such a way that the output is a moving window of 3 digits at a time. So I get – [“731”, “316”, “167”, “671”, “717”] How would the approach be? Straightforward way is to put in for-loop and iterate. But
Tag: split
Pythonic way to split a list into first and rest in Python 2.x?
I think in Python 3 I’ll be able to do: which is exactly what I want, but I’m using 2.6. For now I’m doing: This is fine, but I was just wondering if there’s something more elegant. Answer Basically the same, except that it’s a oneliner. Tuple assigment rocks. This is a bit longer and less obvious, but generalized for
Product code looks like abcd2343, how to split by letters and numbers?
I have a list of product codes in a text file, on each line is the product code that looks like: abcd2343 abw34324 abc3243-23A So it is letters followed by numbers and other characters. I want to split on the first occurrence of a number. Answer Or, if you want to split on the first occurrence of a digit: d+