| New Reply |
GO37H3's n00b to 1337 programming/comp thread |
Share Thread | Thread Tools |
| Dec2-10, 11:58 PM | #52 |
|
|
GO37H3's n00b to 1337 programming/comp thread
You're a little bit behind the times. ;)
|
| Dec3-10, 10:59 AM | #53 |
|
Blog Entries: 3
|
as for this: |
| Dec3-10, 09:43 PM | #54 |
|
|
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)
|
| Dec6-10, 09:25 PM | #55 |
|
|
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 |
| Dec6-10, 09:34 PM | #56 |
|
|
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]
|
| Dec6-10, 09:38 PM | #57 |
|
Blog Entries: 3
|
|
| Dec7-10, 12:18 AM | #58 |
|
|
DaveE |
| Dec7-10, 08:47 AM | #59 |
|
Blog Entries: 3
|
The python's sort of advanced, but he got the answer from stackoverflow. |
| Dec7-10, 10:03 AM | #60 |
|
|
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: Code:
http://www.everything2.com/index.pl?node_id=429011,www.google.com,http://www.physicsforums.com/forumdisplay.php?f=165 Code:
1) http://www.everything2.com/index.pl?node_id=429011 2) www.google.com 3) http://www.physicsforums.com/forumdisplay.php?f=165 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 1) "pl?node_id=429011", 17 characters 2) "com", 3 characters 3) "php?f=165", 9 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". Now what if it were a list of e-mail addresses? Code:
foobar@myurl.com,john.doe@example.org,"Mrs. Abigail Whithersby"@junk.com Code:
1) foobar@myurl.com 2) john.doe@example.org 3) "Mrs. Abigail Whithersby"@junk.com Code:
1) A) foobar@myurl B) com 2) A) john B) doe@example C) org 3) A) "Mrs B) Abigail Whithersby"@junk C) com 1) "com", 3 characters 2) "org", 3 characters 3) "com", 3 characters 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 |
| Dec8-10, 08:14 AM | #61 |
|
|
|
| Dec8-10, 08:46 AM | #62 |
|
|
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 |
| Dec8-10, 10:36 AM | #63 |
|
Blog Entries: 3
|
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)
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' |
| Dec8-10, 12:19 PM | #64 |
|
|
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;
}
}
DaveE |
| New Reply |
| Thread Tools | |
Similar Threads for: GO37H3's n00b to 1337 programming/comp thread
|
||||
| Thread | Forum | Replies | ||
| Intro to Comp Programming | Academic Guidance | 6 | ||
| Comp sci (C programming) | Engineering, Comp Sci, & Technology Homework | 1 | ||
| Is being good at programming necessary for comp sci major? | Academic Guidance | 4 | ||
| Why does BLS project a much greater demand for Comp Scientists than Comp Engineers? | Career Guidance | 3 | ||
| New to Comp. Programming | Programming & Comp Sci | 8 | ||