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.
#51
story645
678
2
G037H3 said:
I'll see what other people think of it as well. >.<
I've been using it lately and recommend it as it's pretty well behaved/the easiest of the lot. Pythonwin is also pretty decent, but can be somewhat cranky.
I know I don't *need* one. But I want one. Preferably with a black background and pretty colors. :O
Python cmd line does that, so does ipython, but both are shells, not ides. Actually, you can also just configure IDLE to look like that.
basics out of the way you start trying to learn a web framework such as Django or Pylons.
Start with bottle, as it's just one python file.
The standard 'introductory' book on algorithms is CLRS.
It's considered the bible by most of the computer scientists I've met.
You might want to check out project euler and dive into python while you're at it, and
Figured the information hadn't been said yet, so why not?
as for this:
I play a lot, mixing and matching. I'll write something one way and then try to think of two other ways of doing the same thing. Right now, I'm doing lots of stuff with lists and dictionaries, convoluted manipulations. I'm starting to move towards making useful stuff though. :)
Why not write a little address book script? It's a mix of lists, dictionaries, loops, and i/o.
#54
G037H3
280
2
story645 said:
Why not write a little address book script? It's a mix of lists, dictionaries, loops, and i/o.
I'll try that. Will try to remember to post result in next day or two.
FizzBuzz (some people really can't do this?...):
Code:
for i in range(1, 101):
if i % 15 == 0:
print ('fizzbuzz')
elif i % 3 == 0:
print ('fizz')
elif i % 5 == 0:
print ('buzz')
else:
print(i)
#55
davee123
671
4
G037H3 said:
FizzBuzz (some people really can't do this?...):
I've never tried it, but we did have some people that might not have been able to. We once were interviewing people for Perl jobs, and someone claimed that they had spent the last 3 years programming with Perl's Mason library for Amazon. Sounded OK, but then we asked them this simple question:
Write a Perl program that does the following:
1. Opens a file whose name is given on the commandline
2. Replaces all occurrences of 'Y' with 'K'
3. Writes the results to a new file with ".mod" appended to the original filename
4. Runs the external command "swizzle" with the original filename as an argument
The applicant started to write a combination of Perl and C, and couldn't finish the program. It was just sad. We expect that the 3 years of Perl experience reported were simply adjusting the HTML parts of the Mason templates, and not really working with the underlying Perl.
I think the sad part isn't so much that people can't do it-- it's that people that can't do it actually APPLY for programming jobs.
DaveE
#56
G037H3
280
2
Given a string containing a series of addresses, separated by commas, here's a list comprehension to create a list of those addresses with domain names of 2-4 characters:
Code:
[url for url in urlstring.split(',') if 2 <= len(url.split('.')[-1]) <=4]
#57
story645
678
2
davee123 said:
I think the sad part isn't so much that people can't do it-- it's that people that can't do it actually APPLY for programming jobs.
I think it's because a lot of people don't realize just quite how bad they are. I thought I was a pretty decent coder when I was a freshie, (I'd been coding for a few years at that point) and a friend decided to tutor me in C. It was a disaster and I realized that I was a lousy coder, and it took a couple of years and lots of coding intensive research later to get my coding up to half-decent. I think a lot of students refuse to hit the "I'm lousy" stage and therefore don't put in the time coding and poring over documentation to get to the half-decent stage.
#58
davee123
671
4
G037H3 said:
Given a string containing a series of addresses, separated by commas, here's a list comprehension to create a list of those addresses with domain names of 2-4 characters:
Code:
[url for url in urlstring.split(',') if 2 <= len(url.split('.')[-1]) <=4]
I admittedly don't know Python, but this seems wrong. What sort of "addresses" are you assuming your input contains? What's a sample input and your expected resultant list?
DaveE
#59
story645
678
2
davee123 said:
I admittedly don't know Python, but this seems wrong.
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.
Last edited:
#60
davee123
671
4
story645 said:
It actually works just as expected. What do you think is wrong about it? The python looks fine to me, and I use python all the time.
Guh, well, ok-- I'd still just like a sample expected input and output.
To start, it says "urlstring", which implies that it's a list of URLs, but the text says "addresses", which implies "e-mail addresses". Assuming you had a list of URLs:
Next, you're splitting on "." (which I assume means "." and not the regexp of "any character" as it might in Perl), which would split it into a resulting set of arrays:
Code:
1)
A) http://www
B) everything2
C) com/index
D) pl?node_id=429011
2)
A) www
B) google
C) com
3)
A) http://www
B) physicsforums
C) com/forumdisplay
D) php?f=165
Next, it only looks at the ones where the final element in the array is between 2 and 4 characters:
So, none of those look like domain names that it's comparing against-- the closest is "com" in "www.google.com", but while that's TECHNICALLY a domain name, most people would think of the domain name as "google.com" (the subdomain), and not simply "com".
So, in that case, if it was splitting on "@" instead of ".", it would make sense, but I don't think that's what it's doing. And again, TECHNICALLY those are "domain names", but not how people think of them-- you'd expect it to be pulling out the full "example.org", etc., and not just the "org" part.
Anyway, am I misinterpreting something?
DaveE
Last edited:
#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.
#62
davee123
671
4
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:
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])