For-Loops Are Torture
Apparently, my code doesn't work for larger words... Now I have to sit and think about what I am feeding into the for loop and what it is giving me as an output. I have to use a pen and paper for that and this is why for-loops for me are torture. I think I need to add sort. return max1 i=0 wl2 = [] for word in wl: if wl[-1] == ew: l9 = [] print(l9) else: for i in range(len(wl)-1): if dist1(ew,wl[i]) >= dist1(ew,wl[i+1]) and dist1(bw,wl[i]) <= dist1(bw,wl[i+1]): wl2.append(wl[i]) break print([bw] + wl2 + [ew]) worldladder(bw,ew,wl) ['hit', 'hot', 'lot', 'log', 'cog'] start1 = 'smart' end1 = 'money' words = ['cock', 'soars', 'stars', 'conks', 'cones', 'coney', 'soaks', 'socks', 'sucks', 'money'] worldladder(start1,end1,words) ['smart', 'stars', 'conks', 'cones', 'soaks', 'sucks', 'money']
Скриншот поста с задачей на Python: автор пытается отладить алгоритм word ladder, который превращает одно слово в другое через цепочку промежуточных слов. Шутка в том, что логика циклов настолько запутанная, что автору приходится разбирать входные и выходные данные ручкой и бумагой и называет for-циклы пыткой. EN: A screenshot of a post about a Python task: the author is debugging a word ladder algorithm that transforms one word into another through a chain of intermediate words. The joke is that the loop logic is so confusing that the author has to analyze the inputs and outputs with pen and paper and calls for-loops torture.
social media post / пост в соцсетиprofile photo / фотография профиляcomputer screen / экран компьютераPython code / код на PythonJupyter Notebook / Jupyter Notebookcode editor / редактор кодаword ladder algorithm / алгоритм word ladderfor loop / цикл forpen and paper / ручка и бумагаtext output / текстовый выводmouse cursor / курсор мышиwhite background / белый фон
- @right_wing_dev_squads / 2920 2021-11-17
- Type
- image
- Size
- 792×800 · 110.4 KiB
- Mood
- frustrated, relatable
- Language
- en
- Added