Python Forum
String index out of bounds ( Python : Dict )
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
String index out of bounds ( Python : Dict )
#2
Please use proper tags when posting.

Here is a working example

#! /usr/bin/env python3

roman = {
    'I':1, 'V':5, 'X':10, 'L':50, 'C':100, 'D':500, 'M':1000
}

def convert(rn):
    converted = []
    for val in rn:
        if val in roman.keys():
            converted.append(roman[val])
    return sum(converted)
print(convert('XVI'))
Output:
16
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply


Messages In This Thread
RE: String index out of bounds ( Python : Dict ) - by menator01 - Jun-25-2020, 04:28 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  IndexError: index 10 is out of bounds for axis 0 with size 10 Mehboob 11 2,506 Sep-14-2023, 06:54 AM
Last Post: Mehboob
  I'm getting a String index out of range error debian77 7 2,540 Jun-26-2022, 09:50 AM
Last Post: deanhystad
  For loop index out of bounds armitron121 2 2,788 Feb-08-2022, 04:23 PM
Last Post: armitron121
  string index out of range jade_kim 4 2,750 Jan-13-2021, 05:41 AM
Last Post: jade_kim
  IndexError: index 10 is out of bounds for axis 0 with size 1 vahid89 1 12,451 Jan-07-2021, 06:19 PM
Last Post: deanhystad
  when this error rise?index 28 is out of bounds for axis 0 with size 13 abbaszandi 1 5,136 Nov-10-2020, 08:46 PM
Last Post: deanhystad
  TypeError: __repr__ returned non-string (type dict) shockwave 0 3,282 May-17-2020, 05:56 PM
Last Post: shockwave
  Python 2 to 3 dict sorting joshuaprocious 2 73,312 May-14-2020, 03:28 PM
Last Post: joshuaprocious
  IndexError: index 0 is out of bounds for axis 0 with size 0 error tmhsa 5 4,630 Apr-25-2020, 01:15 PM
Last Post: tmhsa
  Sort a dict in dict cherry_cherry 4 96,492 Apr-08-2020, 12:25 PM
Last Post: perfringo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020