What you have done is quite ok.
Maybe you can directly use a list comprehension, and use the join
method to regroup the terms, separated by a &
(no need to remove the last character).
dico = {'a':'A', 'b':'B'}
x = "&".join( "%s=%s"%item for item in dico.items() )
EDIT: the urllib.urlencode
will also ensure that are converted in ASCII, that is not done, here. But this is the home-made pythonic way to do it ;-) (no extra library required)
EDIT2: since the question was "how to write this code in a more pythonic way", I believe that my answer is still correct (only one simple list comprehension).
Of course, since the urllib.urlencode
is doing it, with correct encoding, it's better to use it.