def dailyTemp(T): ans_list = [] s = Stack() while abs(i) < len(T): if s.isEmpty() is True: s.push(i) ans_list[i] = 0 i = i - 1 else: if T[i] >= s.peek(): s.pop() i = i - 1 else: ans_list[i] = s.top() - i s.push(i) i = i - 1 return ans_list
def doWhileToWhile(fo, file): in_file = [] with fo as f: in_file = f.readlines() out_file = [] exist_while = 1 lookupDo = "do{" lookupWhile = "}while" lookupReturn = "return" z = 0 while exist_while: out_file = [] print str(z) + "dsds" z = z + 1 start = "" end = "" start_index = -1 end_index = -1 st = Stack() st_index = Stack() i = 0 for i in range(len(in_file)): print in_file[i] if lookupReturn in in_file[i]: continue if lookupDo in in_file[i]: st.push(in_file[i]) print st.size() + 10000000 st_index.push(i) elif lookupWhile in in_file[i]: if st.size() == 1: start = st.peek() start_index = st_index.peek() print in_file[i] st.pop() st_index.pop() end = in_file[i] end_index = i break else: st.pop() st_index.pop() if start_index == end_index or start_index == -1 or end_index == -1: if not st.isEmpty(): print "The code given as input is wrong. Please, check and try again.\n Line No:" + st.top( ) break end = end.replace("}while", "while") end = end.replace(";", "") end = end + "{\n" print str(end_index) + "ss" + str(start_index) for i in range(len(in_file)): if i != start_index and i < end_index: out_file.append(in_file[i]) for i in range(len(in_file)): if i == start_index: out_file.append(end) elif i == end_index: out_file.append("}\n") elif i > start_index: out_file.append(in_file[i]) in_file = [] in_file = out_file print in_file with file as f: f.writelines(in_file) return