longcop.blogg.se

Change endnotes from roman to arabic numerals in word for mac
Change endnotes from roman to arabic numerals in word for mac












change endnotes from roman to arabic numerals in word for mac
  1. #Change endnotes from roman to arabic numerals in word for mac generator#
  2. #Change endnotes from roman to arabic numerals in word for mac code#

Okay, so now you converted something like MDCCCLXXIX to and the goal is to get 1879.

#Change endnotes from roman to arabic numerals in word for mac generator#

Either simply l = list(convert_individual_letters('MDC')) to consume the whole generator or with a for loop: for n in convert_individual_letters('MDC').

  • You get to name your function, which improves clarityĪnd you can use this function in two ways.
  • #Change endnotes from roman to arabic numerals in word for mac code#

    It's a generator that can directly be used in a for loop (it can even more efficient if the rest of your code use generators too because you won't iterate over the whole string unless you asked for it - however it's not the case here).Note that you could transform this into a generator function, like this: def convert_individual_letters(roman_string): You even get an exception if the letter is not in your dictionary, while your previous code silently ignored the issue (you had no else case). Now you can rewrite this whole loop like this: for c in t: Also, whenever you populate a list by creating an empty list and appending to it repeatedly, that is a good candidate for a list comprehension: trans = Lookups are typically done in Python using a dictionary. That's not what I would call a "format" - I would call it a "result".Īs I mentioned before, l is a cryptic name. It happens to be what you wrote as the comment! Similarly, I'd call the inverse function encode_roman_numeral(num).

    change endnotes from roman to arabic numerals in word for mac

    (And by "Arabic", we mean 0123456789, not ٠١٢٣٤٥٦٧٨٩.)īased on these concerns, I'd call it decode_roman_numeral(roman). It's just an abstract integer, which is conventionally rendered for you as base-ten Arabic digits when str() is called on it (whether explicitly or implicitly). It's not Arabic, nor is it even in base ten. Strictly speaking, the result is an int.Why is the parameter named t - what does it stand for?."get" implies retrieving something that already exists.Get_arabic_numbers(t) is not really named appropriately: The variable names were generally not helpful: l, i, t, c, li were all cryptic. The comments were generally helpful, but the code itself could have been easier to understand if it were shorter and more expressive. # If the number is at least 1 but smaller than 10 # If the number is at least 10 but smaller than 100 # If the number is at least 100 but smaller than 1000įormat = format + encode(l, c, 'I', 'V', "IX") # They are in the wrong order, so the list has to be reversedįormat = format + encode(l, c, 'C', 'D', "CM")įormat = format + encode(l, c, 'X', 'L', "XC") # int is not iterable, so I wrote this to get the digits # Special case 9.3: 900 depends on 1000, so it's 'CM' # Special case 9.2: 90 depends on 1000, so it's 'XC' # Special case 9.1: 9 depends on 10, so it's 'IX' # Convert from roman numeral to arabic number I got an idea to make a Roman/Arabic number converter, and I would like to hear your thoughts, where I could improve it, if there are Python specific things that I missed, so on and so forth.














    Change endnotes from roman to arabic numerals in word for mac