I am new to python and I have heard a lot about "Pythonic" work arounds to common tasks. I wrote the following script for a project I'm working on where it needed to pick a random string from a list of strings and break the string into a key and value. The script worked for that purpose but it got me wondering about the way senior developers think about coding.
As a senior developer, how would you think about solving a similar problem?
-
What approach would you take in writing this type of script and why?
-
How would you decide on the modules to use?
-
What did I do wrong or right and why?
-
Would you write the code as fast as possible or spend more time on it?
'''
import random
import re
def add_list(wordlist):
newword = str(re.split("=", random.choice(wordlist)))
print(newword)
output = open('Logfile.txt', 'a')
output.write("\n" + newword)
return output
add_list(wordlist = ['1=one', '2=two', '3=three', '4=four',])
'''
Aucun commentaire:
Enregistrer un commentaire