As a lispy thinker, my brain wants to tell you to make those for loops into comprehensions, but my work brain is telling me that my coworkers would have me drawn and quartered to make your "find-one-difference" a one-liner!
Kudos on how neat this looks. I find python and ruby to be difficult to make look "clean" when I write it.
Ryan is an engineer in the Sacramento Area with a focus in Python, Ruby, and Rust. Bash/Python Exercism mentor. Coding, physics, calculus, music, woodworking. Looking for work!
I ended up using zip to help with the comparison if the strings in part 2:
#!/usr/bin/env python
fromcollectionsimportCounterdeffind_similar_box_ids(all_box_ids):forbox_id_1inall_box_ids:forbox_id_2inall_box_ids:# This is kind of a naive Levenshtein distance!
letter_pairs=zip(box_id_1,box_id_2)duplicates=list(filter(lambdapair:pair[0]==pair[1],letter_pairs))iflen(duplicates)==len(box_id_1)-1:return''.join(pair[0]forpairinduplicates)if__name__=='__main__':withopen('2-input.txt')asbox_file:all_box_ids=box_file.read().splitlines()print(find_similar_box_ids(all_box_ids))
Nice! Definitely think that's the easiest way to do number 1. Zip also makes sense for the second, though not using it allowed me to do the early return!
Python solutions!
part 1
part 2 -- this one feels clunky to me.
As a lispy thinker, my brain wants to tell you to make those for loops into comprehensions, but my work brain is telling me that my coworkers would have me drawn and quartered to make your "find-one-difference" a one-liner!
Kudos on how neat this looks. I find python and ruby to be difficult to make look "clean" when I write it.
10 points for the variable name βthrice!β
My part one ended up looking super similar!
I ended up using
zip
to help with the comparison if the strings in part 2:Nice! Definitely think that's the easiest way to do number 1. Zip also makes sense for the second, though not using it allowed me to do the early return!
True!