![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#11 |
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5
![]() |
There's also Beautiful Soup, which is supposed to be quite highly regarded.
|
|
|
|
|
|
#12 |
|
Programming Guru
![]() |
Yeah, I heard about Beautiful Soup, but not htmlib. I really don't want to import an entire parsing library when all I need to do is parse one kind of tag with one function.
|
|
|
|
|
|
#13 |
|
The Oblivious One
Join Date: May 2005
Location: Ontario, Canada
Posts: 644
Rep Power: 4
![]() |
I'm sure there is an easier way (there always seems to be one in Python :p), but I made a little reverser function.
It will take either a string, tuple, or list and return the same data-type, reversed. def reverse(ls): """Reverses and return a string, list, or tuple.""" res = [ls[len(ls) - x] for x in range(1, len(ls) + 1)] if types.StringType == type(ls): res = "".join(res) elif types.TupleType == type(ls): res = tuple(res) return res
__________________
Dr. Zoidberg: [ecstatic] I'm going to a movie... with FRIENDS! Last edited by Jessehk; Mar 10th, 2006 at 4:51 PM. |
|
|
|
|
|
#14 |
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5
![]() |
Python 2.4 has the "reversed" function, which iterates over a sequence backward. So you could do this:
def reverse(s):
r = reversed(s)
if type(s) == list: return list(r)
if type(s) == tuple: return tuple(r)
if type(s) == str: return "".join(r)def reverse(s):
return { str : "".join, list : list, tuple : tuple }[type(s)](reversed(s)) |
|
|
|
|
|
#15 |
|
The Oblivious One
Join Date: May 2005
Location: Ontario, Canada
Posts: 644
Rep Power: 4
![]() |
I didn't know about the reversed() function.
*And I think that is the most clever use of dictionaries I have ever seen. :eek ![]() Thanks Arevos ![]()
__________________
Dr. Zoidberg: [ecstatic] I'm going to a movie... with FRIENDS! |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|