Network MAC address conversion to IPv6 link-local address
Note that the purpose of the hex() function is to produce a hexadecimal integer literal (a string that can be used in Python source code), which is why it returns a hex value with the 0x prefix. Use the format() function instead, as it gives you much more control over the output.

For example, format(value, '012x') formats the integer value to a 12-digit hexadecimal (using lowercase digits), padding out the result to the minimum width with leading zeros as needed:

&gt;&gt;&gt; mac_value = 0x237702d2ff9b
&gt;&gt;&gt; format(mac_value, '012x')
'237702d2ff9b'
&gt;&gt;&gt; format(42, '012x')
'00000000002a'


In this case, I'd actually split out the various bytes of the MAC address binary value that make up the IPv6 parts, and use str.format() to interpolate those into the IPv6 string.

def mac_to_ipv6_linklocal(mac):
    # Remove the most common delimiters; dots, dashes, etc.
    mac_value = int(mac.translate(None, ' .:-'), 16)

    # Split out the bytes that slot into the IPv6 address
    # XOR the most significant byte with 0x02, inverting the 
    # Universal / Local bit
    high2 = mac_value &gt;&gt; 32 &amp; 0xffff ^ 0x0200
    high1 = mac_value &gt;&gt; 24 &amp; 0xff
    low1 = mac_value &gt;&gt; 16 &amp; 0xff
    low2 = mac_value &amp; 0xffff

    return 'fe80::{:04x}:{:02x}ff:fe{:02x}:{:04x}'.format(
        high2, high1, low1, low2)


I followed the PEP 8 whitespace recommendations to format the code here; whitespace around operators and after commas, for example.

In Python, we usually don't strive for shorter code; we aim for readable code. Sometimes you can express an algorithm in a very concise and readable way, but avoid code-golfing for the sake of compactness.

Python 3.3 added a ipaddress module; this module does not however include a utility to generate an IPv6 address from a given MAC address.