Reverse keys and values in dictionary

Татьяна Паскевич

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

Jatin Bansal

Татьяна Паскевич, 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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Reverse keys and values in dictionary

From Dev

Reverse multiple values with keys in dictionary

From Dev

How to reverse dictionary items and list keys grouped by common values

From Dev

Python : reverse keys and values in dictionary considering strings and not caracters

From Dev

To reverse a dictionary and display values

From Dev

List to dictionary with keys and values

From Dev

Swap keys for values in dictionary?

From Dev

changing values of dictionary keys

From Java

Reverse HashMap keys and values in Java

From Dev

Retrieving values if keys of the dictionary are in frozensets

From Dev

Merging dictionary keys if values the same

From Dev

Join keys and values from Dictionary

From Dev

Find dictionary keys with duplicate values

From Dev

Swap keys and values in dictionary with underscore

From Dev

Python replacing keys with values in dictionary

From Dev

Different list values for dictionary keys

From Dev

keys with multiple values in a dictionary (Python)

From Dev

Replacing placeholders with dictionary keys/values

From Dev

Assigning values to keys in a mutable dictionary

From Dev

Retrieving values if keys of the dictionary are in frozensets

From Dev

Intersection of Dictionary based on keys and values

From Dev

Match keys to values in dictionary in python

From Dev

Different list values for dictionary keys

From Dev

Mapping keys to values in Python dictionary

From Dev

Updating a dictionary with values and predefined keys

From Dev

Match dictionary keys and values in new dictionary

From Dev

Match dictionary keys and values in new dictionary

From Dev

How to reverse a dictionary (whose values are lists) in Python?

From Dev

Build a new dictionary from the keys of one dictionary and the values of another dictionary

Related Related

  1. 1

    Reverse keys and values in dictionary

  2. 2

    Reverse multiple values with keys in dictionary

  3. 3

    How to reverse dictionary items and list keys grouped by common values

  4. 4

    Python : reverse keys and values in dictionary considering strings and not caracters

  5. 5

    To reverse a dictionary and display values

  6. 6

    List to dictionary with keys and values

  7. 7

    Swap keys for values in dictionary?

  8. 8

    changing values of dictionary keys

  9. 9

    Reverse HashMap keys and values in Java

  10. 10

    Retrieving values if keys of the dictionary are in frozensets

  11. 11

    Merging dictionary keys if values the same

  12. 12

    Join keys and values from Dictionary

  13. 13

    Find dictionary keys with duplicate values

  14. 14

    Swap keys and values in dictionary with underscore

  15. 15

    Python replacing keys with values in dictionary

  16. 16

    Different list values for dictionary keys

  17. 17

    keys with multiple values in a dictionary (Python)

  18. 18

    Replacing placeholders with dictionary keys/values

  19. 19

    Assigning values to keys in a mutable dictionary

  20. 20

    Retrieving values if keys of the dictionary are in frozensets

  21. 21

    Intersection of Dictionary based on keys and values

  22. 22

    Match keys to values in dictionary in python

  23. 23

    Different list values for dictionary keys

  24. 24

    Mapping keys to values in Python dictionary

  25. 25

    Updating a dictionary with values and predefined keys

  26. 26

    Match dictionary keys and values in new dictionary

  27. 27

    Match dictionary keys and values in new dictionary

  28. 28

    How to reverse a dictionary (whose values are lists) in Python?

  29. 29

    Build a new dictionary from the keys of one dictionary and the values of another dictionary

HotTag

Archive