Hacker News new | past | comments | ask | show | jobs | submit login

I only use the [x] * n form of array initialization for primitive types (int,float,bool,string). So

  #good
  a = [True] * 8 # bool is primitive
  b = [[True] * 8 for i in range(8)] # range creates new lists each time

  #bad
  a = [{}] * 8 # dict is not a primitive
  b = [[True] * 8] * 8 # list is not a primitive



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: