GO37H3's n00b to 1337 programming/comp thread

  • Thread starter Thread starter G037H3
  • Start date Start date
  • Tags Tags
    Thread
Click For Summary

Discussion Overview

The discussion revolves around the learning journey of a participant interested in programming, particularly focusing on foundational concepts and metaskills rather than specific programming languages. The scope includes theoretical aspects of programming, prerequisites for learning, and resources for self-education.

Discussion Character

  • Exploratory
  • Technical explanation
  • Conceptual clarification
  • Debate/contested

Main Points Raised

  • One participant emphasizes the importance of learning general concepts in programming that can be applied across various fields, rather than focusing on specific languages.
  • Another participant shares their experience learning Java and expresses confusion when encountering Python, suggesting that Java's complexity has shaped their perspective.
  • Questions are raised about the relevance of reading foundational texts on logic, such as those by George Boole, with some participants suggesting that while they may not directly apply to programming skills, they could be personally enriching.
  • Recommendations are made for foundational reading materials, including "Structure and Interpretation of Computer Programming," which focuses on programming thought processes rather than specific languages.
  • Discussion includes the suggestion to explore automata theory as a way to build a deeper understanding of computer science concepts, although its immediate applicability to introductory programming is questioned.
  • Participants discuss the potential benefits of learning web frameworks like Django or Pylons for practical contracting work after gaining some programming basics.
  • One participant mentions the importance of real-world experience in understanding customer needs for contracting work, indicating that programming skills alone may not suffice.
  • Resources such as coding practice websites are shared to aid in learning Python.

Areas of Agreement / Disagreement

Participants express differing views on the best approach to learning programming, with some advocating for Python as a first language due to its focus on applications, while others highlight the complexity of Java as a point of confusion. There is no consensus on the immediate relevance of foundational logic texts to programming skills.

Contextual Notes

Participants acknowledge the potential limitations of their suggestions, including the varying applicability of foundational texts to practical programming skills and the challenges of transitioning from learning to real-world application.

  • #61
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.
 
Technology news on Phys.org
  • #62
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. 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:

grep /^([a-z0-9\-]+\.)*[a-z0-9]{2,4}$/i, split /,/,$url;

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
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:
Code:
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'
regex = re.compile('''[[a-zA-Z0-9\-\.]+\.]*[a-zA-Z0-9\-]{2,4}\.[^\.\,]+''')
url_list = regex.findall(urls)

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
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:

Code:
@list = split /,/,$urls;
@final_list = ();
foreach my $domain (@list) {
  @parts = split /\./,$domain;
  if(length($parts[-1]) >= 2 && length($parts[-1]) <= 4) {
    push @final_list,$domain;
  }
}

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
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])
list is a reserved word in python
 

Similar threads

Replies
16
Views
3K
  • · Replies 43 ·
2
Replies
43
Views
7K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 15 ·
Replies
15
Views
4K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 397 ·
14
Replies
397
Views
21K
  • · Replies 14 ·
Replies
14
Views
3K
  • · Replies 1 ·
Replies
1
Views
890
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 32 ·
2
Replies
32
Views
4K