Reducing a Python Script Does anyone have any suggestions as to how I could shorten this program?

_=map(ord,raw_input());_=[10if y==88else 0if y==45else 58-_[x-1]if y==47else y-48for x,y in enumerate(_)];t=0;exec('t+=sum(_[:2+(_[0]+_[1]&gt;=10)]);_=_[2-(_[0]==10):];'*10);print t


Run it online

I'd like to write a bowling calculator. I'm fairly proficient in python so I chose that language. 

The trick is that the input string is made up of frames not split by white-space and the spares, strikes, and misses are marked by /, X, and - respectively. (note that there are no 0 in the code, - is used instead)

Here is an example line X7/9-X-88/-6XXX81, this line would have a score of 167.

As you can see, most of my characters are spent on mapping these special characters to their actual bowl scores. I do this by taking their ord values and then replacing the X and - with 10 and 0 respectively. I then find the / rolls and set their value as ten minus the previous roll.

After this, I calculate the final game score by looping over 10 frames (the size of a line of bowling), chunking the line array based on if the  frame was a strike spare or normal roll, and then reducing the array going forward.

I feel like this is the best way to perform this challenge as a golf challenge, but I'm not sure if I'm reducing it enough.
1.

The portion 2+(_[0]+_[1]&gt;=10) could be rewritten as 2+(_[0]+_[1]&gt;9) to save two bytes. In a similar vein 2-(_[0]==10) can be rewritten as 2-(_[0]&gt;9), since 10 is the only possible value greater than 9.



a=map(ord,raw_input());a=[10if y==88else 0if y==45else 58-a[x-1]if y==47else y-48for x,y in enumerate(a)]
t=0;exec('t+=sum(a[:2+(a[0]+a[1]&gt;9)]);a=a[2-(a[0]&gt;9):];'*10);print t


Try it online!

(I also renamed _ to a, because even though it's code-golf we don't have to make it unreadable)

2.

You can also use a dictionary instead of conditionals to saves some bytes.

a=raw_input();a=[{y:ord(y)-48,'X':10,'-':0,'/':58-ord(a[x-1])}[y]for x,y in enumerate(a)]
t=0;exec('t+=sum(a[:2+(a[0]+a[1]&gt;9)]);a=a[2-(a[0]&gt;9):];'*10);print t


Try it online!

3.

Don't enumerate.  enumerate tends to be too long for it's own good.  Here you want to get the last character, which can better be acheived with a zip.



a=raw_input();a=[{y:ord(y)-48,'X':10,'-':0,'/':58-ord(x)}[y]for x,y in zip('-'+a,a)]
t=0;exec('t+=sum(a[:2+(a[0]+a[1]&gt;9)]);a=a[2-(a[0]&gt;9):];'*10);print t


Try it online!



If you combine this with @user202729's two tips you get 149 bytes.

a=raw_input();a=[[10,0,58-ord(x),ord(y)-48]['X-/'.find(y)]for x,y in zip('-'+a,a)]
t=0;exec't+=sum(a[:2+(a[0]+a[1]&gt;9)]);a=a[2-(a[0]&gt;9):];'*10;print t


Try it online!



Here's another version that is also 149 bytes:

a=raw_input();a=[['-123456789X'.find(y),58-ord(x)][y=='/']for x,y in zip('-'+a,a)]
t=0;exec't+=sum(a[:2+(a[0]+a[1]&gt;9)]);a=a[2-(a[0]&gt;9):];'*10;print t


Try it online!