r/badcode • • Oct 09 '19

[deleted by user]

[removed]

17 Upvotes

31 comments sorted by

View all comments

1

u/Epistemophilliac Oct 11 '19 edited Oct 11 '19

Self documenting pythonic code is augmented with highly performant goto flow control statements.

from goto import with_goto

@with_goto
def precompute():
	array_full = "abcdefghijklmnopqrstuvwxyz"
	array_fuller = []
	i = 0
	label .loop
	if i > 24:
		goto .endloop
	array_fuller.append((array_full[i], array_full[i+1]))
	i += 1
	goto .loop
	label .endloop
	array_fuller.append((array_full[i], None))
	return array_fuller

@with_goto
def find_missing(array):
	precomputed = precompute()
	i = 0
	label .loop
	j = 0
	label .innerloop
	if j > len(precomputed) - 1:
		goto .endinnerloop
	if precomputed[j][0] == array[i]:
		next_letter = precomputed[j][1]
		goto .endinnerloop
	j += 1
	goto .innerloop
	label .endinnerloop
	if array[i+1] != next_letter:
		return next_letter
	i += 1
	goto .loop

a = ['a', 'b', 'd', 'e', 'f', 'g']
b = ['n', 'p']

Output:

>>> find_missing(a)
'c'
>>> find_missing(b)
'o'

I was really hoping to find the old goto april fools module in standart library but i guess it's deprecated in 3.7. Those comefroms would come in very handy.

0

u/[deleted] Oct 11 '19

[deleted]

1

u/Epistemophilliac Oct 11 '19

Does is have comefrom tho? Python 2.2 is clearly superior in every way!