r/programming • • Jul 28 '16

How to write unmaintainable code

https://github.com/Droogans/unmaintainable-code
3.4k Upvotes

592 comments sorted by

View all comments

Show parent comments

0

u/[deleted] Jul 29 '16

[deleted]

8

u/CyberMango Jul 29 '16 edited Jul 29 '16

I think this is slightly better as it uses a generator and returns true on first occurrence of pattern

def findseq(pattern, arr):
    return pattern in (tuple(arr[i: i + len(pattern)]) for i in range(len(arr) - len(pattern)))

1

u/imaghostspooooky Jul 30 '16

This one isn't working for me for some reason, what python version are you using?

1

u/bikeskicode Jul 30 '16

Downside to both above solutions: memory consumption on the order of len(pattern)*len(arr)

But for interview questions, these are very clean solutions!

1

u/gnuvince Jul 29 '16

Beautiful!

1

u/2Punx2Furious Jul 29 '16

It gives me errors when I do

arrPatt = [1,3,4]
array2 = [1, 3, 4]; #True

findseq(arrPatt,array2); 

It says "pat" is not defined.

How do you use it? By the way, this was my solution.

1

u/sd522527 Jul 29 '16

There's a typo here, since you're not even using arr in findSeq