Skip to content

Tarik Billa

  • Web Development
    • html
    • vue.js
    • laravel
    • css
    • javascript
    • jquery
    • node.js
    • php
    • asp.net
  • Programming
    • python
    • java
    • c
    • c++
    • c#
  • git
  • android

reverse

Reverse / invert a dictionary mapping

September 6, 2022 by Tarik

Python 3+: inv_map = {v: k for k, v in my_map.items()} Python 2: inv_map = {v: k for k, v in my_map.iteritems()}

Categories python Tags dictionary, mapping, python, reverse Leave a comment

Traverse a list in reverse order in Python [duplicate]

September 6, 2022 by Tarik

Use the built-in reversed() function: >>> a = [“foo”, “bar”, “baz”] >>> for i in reversed(a): … print(i) … baz bar foo To also access the original index, use enumerate() on your list before passing it to reversed(): >>> for i, e in reversed(list(enumerate(a))): … print(i, e) … 2 baz 1 bar 0 foo Since … Read more

Categories python Tags loops, python, reverse Leave a comment
Newer posts
← Previous Page1 … Page6 Page7

Tarik Billa

Software Engineer
tarikbilla@gmail.com
+8801884414000
  • Reuse a hash in YAMLApril 17, 2024
  • Dockerfile: how to redirect the output of a RUN command to a variable?April 16, 2024
  • How to cd to a directory with spaces in the directory name?April 16, 2024
  • Maximum MIME type length when storing the type in a databaseApril 16, 2024
  • What is the difference between Unit, Integration, Regression and Acceptance Testing?April 16, 2024
© 2026 Tarik Billa