[Sublist] Fix existing approaches & add new ones#4190
Conversation
also move the note about magic values into `introduction.md` and remove unverified statement about performance
|
@BethanyG, if I use a slightly modified version of your Sublist solution for a |
If that modification has lead to a whole new approach, I'd just put yourself as the author. I am happy being left off. My name is next to so much stuff, no need to invent more. 😄 |
|
It's pretty much the same approach, the modifications are more minor. Here's the code: SUBLIST = 1
SUPERLIST = 2
EQUAL = 3
UNEQUAL = 4
def sublist(list_one, list_two):
if list_one == list_two:
return EQUAL
if not (list_one and list_two):
return SUPERLIST if list_one else SUBLIST
shorter, longer = sorted((list_one, list_two), key=len)
for index in range(len(longer)):
if longer[index : index + len(shorter)] == shorter:
return SUPERLIST if longer is list_one else SUBLIST
return UNEQUAL |
|
still happy being left off. 😄 It's all yours! Edited to add: Needed a bit of a break, so have been doing some knitting. So I might be a tad slower to answer for a bit. Will get back to things in a bit. 😄 |
|
@BethanyG I ended up modifying it a bit more (mostly because I noticed it could be a bit more optimal when the arguments are Edit: Whoops, there was a copy-paste error I missed. Should be ready for real now. |
Fixes formatting and content of Sublist approaches as outlined here. (Will add at least one additional approach.)
Looking closer at the argument in this PR, I have have to say that I don't fully agree with either side. (Look at the changes in
using-strings/content.mdfor further detail.)