I have a dictionary like this:
dict = {'absorbed': ['ah0', 'b', 'z', 'ao1', 'r', 'b', 'd', '#'],
'access': ['ae1', 'k', 's', 'eh1', 's', '#'],
...}
I want to reverse each key and value to get next dictionary:
dict = {'debrosba': ['#', 'd', 'b', 'r', 'ao1', 'z', 'b', 'ah0'],
'ssecca': ['#', 's', 'eh1', 's', 'k', 'ae1'],
...}
and than put symbol "#" at the end of list.
I tried:
for word in words:
word[::-1]
word = word[1:] + word[1]
print word
for keys and
for word in words.values():
word = word[::-1]
symbol = word.pop(0)
print word.append(symbol)
but have got None
Татьяна Паскевич, try this:
d1 = {'absorbed': ['ah0', 'b', 'z', 'ao1', 'r', 'b', 'd', '#'],
'access': ['ae1', 'k', 's', 'eh1', 's', '#']}
d2 = {}
for a in d1:
d2[a[::-1]] = d1[a][::-1]
print d2
Output:
{'ssecca': ['#', 's', 'eh1', 's', 'k', 'ae1'], 'debrosba': ['#', 'd', 'b', 'r', 'ao1', 'z', 'b', 'ah0']}
Cheers!!
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments