I want to scan two integers in python that are separated by a character(any character, not only white space).
In C I can just use
scanf("%d%c%d",&a,&b,&c);
Is there something similar I can do in Python?
I'd use re.split() for this:
In [9]: re.split(r'\D', '1024x768')
Out[9]: ['1024', '768']
or, if you also need to capture the separating character:
In [11]: re.split(r'(\D)', '1024x768')
Out[11]: ['1024', 'x', '768']
(In both cases, apply int() to the strings to convert them to integers.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With