Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

python - Why does this code return a list index error? -


basically it's supposed take set of coordinates , return list of coordinates of it's neighbors. however, when hits here:

if result[i][0] < 0 or result[i][0] >= board.dimensions:     result.pop(i) 

when i 2, gives me out of index error. can manage have print result[2][0] @ if statement throws errors. why happening?

def neighborgen(row,col,board):     """     returns lists of coords of neighbors, in order of up, down, left, right     """      result = []     result.append([row-1 , col])     result.append([row+1 , col])     result.append([row , col-1])     result.append([row , col+1])       #prune off invalid neighbors (such (0,-1), etc etc)      in range(len(result)):          if result[i][0] < 0 or result[i][0] >= board.dimensions:             result.pop(i)         if result[i][1] < 0 or result[i][1] >= board.dimensions:             result.pop(i)      return result  

you indexes iterate on list, , proceed remove elements list. you're going hit index no longer exists. use list comprehension filter instead.

result = [entry entry in result if entry[0] >= 0 ,   entry[0] < board.dimensions , entry[1] >= 0 ,   entry[1] < board.dimensions] 

Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -