The discussion emphasizes the importance of learning programming through a focus on metaskills rather than specific languages, with Python being favored for its forgiving syntax. The participant expresses a desire to understand general concepts applicable to various fields, including engineering and computer science. They seek foundational knowledge in logic and programming, questioning the relevance of reading works by George Boole and other foundational texts. Suggestions are made for resources like "Structure and Interpretation of Computer Programming" and practical frameworks like Django for future work opportunities. The overarching goal is to become employable through programming while maintaining a flexible schedule for other studies.
#61
G037H3
280
2
story645 said:
It actually works just as expected. What do you think is wrong with it? The python looks fine to me, and I use python all the time.
The python's sort of advanced, but he got the answer from stackoverflow.
yeah, I was the asker of that question. I joined stackoverflow and stuff. I had a different solution, but it was more convoluted. I actually don't find list comprehensions to be very advanced at all...it's a lot easier to me than using dictionaries.
yeah, I was the asker of that question. I joined stackoverflow and stuff. I had a different solution, but it was more convoluted. I actually don't find list comprehensions to be very advanced at all...it's a lot easier to me than using dictionaries.
No, it's not very complex-- it's something you'd learn in your first course in programming.
So, why look for only things that have 2-4 letters at the end of the string? If you're looking for valid domains in the list, you probably want to check the validity of the leading characters. Perl-wise, I'd probably do a regex for that:
Dunno how tricky it is to incorporate pattern matches in Python, but it probably makes for a better solution if you're checking for validity rather than something simple like length.
DaveE
Last edited:
#63
story645
678
2
G037H3 said:
yeah, I was the asker of that question. I joined stackoverflow and stuff. I had a different solution, but it was more convoluted.
Convoluted solutions are good-that's how you learn the ins and outs of a language. I usually go through a whole bunch of them before finding the magical list comprehension that does what I need.
I actually don't find list comprehensions to be very advanced at all...it's a lot easier to me than using dictionaries.
They're not, but a list comprehension with two levels of filtering and an uncommon condition is what tipped me off that you probably didn't write it. Be careful with using stackoverflow when you're starting out 'cause the guru answers often obscure the steps you need to learn to be able to craft those answers.
dave said:
Dunno how tricky it is to incorporate pattern matches in Python
Dead simple 'cause the python re library uses perl style regexs. The stackoverflow link actually has the regex variant too:
So the code G037H3 gave acts on the same urls input.
You're pretty much spot on with how it works, but to recap:
urlssplit(') would take urls= 'albatross.org, boogaloo.boolean.net, bedei9.paralex.zenoparadox.herc.gr, takeawalkon.the.wildside,fuzzy.logic.it, bronzeandiron.age, areyou.serious, mydom.dom.net, hun.com'
and split on (',') to return a list of urls
['albatross.org' , 'boogaloo.boolean.net', ..., 'mydom.net', 'hun.com']
then split on ('.') would work on every element in the url list and split it up into lists, so:
['albatross', 'org'], ['boogaloo', 'boolean', 'net'], ... ['mydom', 'net'],...['hun', 'com']
and 2 <= len(url.split('.')[-1]) <=4 tests every last list element, so:
'org', 'net', ..., 'net', 'com'
#64
davee123
671
4
story645 said:
a list comprehension with two levels of filtering and an uncommon condition is what tipped me off that you probably didn't write it.
That's true-- a beginner solution to the same problem would be more step-by-step rather than rolled up into a single line:
Works just as well as the posted solution (probably takes a negligible amount more memory/CPU), but is easier to understand piece by piece.
DaveE
#65
story645
678
2
davee123 said:
That's true-- a beginner solution to the same problem would be more step-by-step rather than rolled up into a single line:
The python equivalent is:
Code:
urlslist = urls.split(',')
final_list = []
for domain in urllist:
parts = domain.split('.')
if ((len(parts[-1]) >=2) and (len(parts[-1])<=4)):
final_list.append(parts[-1])