[Tutor] List slicing and joining

Ben Sherman bensherman at gmail.com
Wed Apr 11 21:58:00 CEST 2007


I've got a list that contain a bunch of information, including the
FQDN of a host.

host_data=['foo.example.com', 'other unimportant data']

I need to seperate the hostname from the domain name.

This is how I'm doing it, and it work, but it seems *really* hacky.
Is there a better (or more pythony) way?

hostname=host_data[0].split(".")[0]
domain=".".join(host_data[0].split(".")[1:])

Thanks,
Ben


More information about the Tutor mailing list