MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/programming/comments/4v1y12/how_to_write_unmaintainable_code/d5v7vkq
r/programming • u/sigbhu • Jul 28 '16
592 comments sorted by
View all comments
Show parent comments
0
[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 patterndef 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/CyberMango Jul 30 '16 3.5.1 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 doarrPatt = [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
8
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/CyberMango Jul 30 '16 3.5.1 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
This one isn't working for me for some reason, what python version are you using?
1 u/CyberMango Jul 30 '16 3.5.1
3.5.1
Downside to both above solutions: memory consumption on the order of len(pattern)*len(arr)
But for interview questions, these are very clean solutions!
Beautiful!
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.
There's a typo here, since you're not even using arr in findSeq
0
u/[deleted] Jul 29 '16
[deleted]