python - string index out of range list iteration -
i new python, not sure on how fix index string out of range. happens right after while loop when want send mylist[i][0] formatting function. pointer on code in general awesome!
def formatting(str1): if str1 == '?': return true else: return false while(i <= len(mylist)): val = formatting(mylist[i][0]) if val == true: str1 = mylist[i] str2 = mylist[i+1] = + 2 format_set(str1, str2) else: if format == true: if (margin + count + len(mylist[i])) <= width: if (i == (len(mylist)-1)): list2.append(mylist[i]) print(" " * margin + " ".join(list2)) break list2.append(mylist[i]) count += len(mylist[i]) += 1 else: print(" " * margin + " ".join(list2)) list2 = [] count = 0 else: temp_margin = margin temp_width = width width = 60 margin = 0 if (margin + count + len(mylist[i])) <= width: if (i == (len(mylist)-1)): list2.append(mylist[i]) print(" " * margin + " ".join(list2)) margin = temp_margin width = temp_width break list2.append(mylist[i]) count += len(mylist[i]) += 1 else: print(" " * margin + " ".join(list2)) list2 = [] count = 0
change
i <= len(mylist)
to
i < len(mylist)
Comments
Post a Comment