-2

I am currently building a program and want to sort data (called component in the code) by week number.

wList = []
thing = []
Wstart = 0

for component in list:

    curDate = component[0]

    year, month, day = (int(x) for x in curDate.split('-'))    
    currentWeek = int(datetime.date(year, month, day).strftime("%V"))

    if Wstart == currentWeek or Wstart == 0:
        wList.append([component, component, component, component])
        Wstart == currentWeek
    else:
        thing.append(Wlist)
        wList = []
        wList.append([component, component, component, component])
        Wstart == currentWeek

Basically I want to reset the Wlist when a new week is available, and store the Wlist in a list called thing, but when I run print(thing) I got "[]".

I appreciate all the help I can get!

L Minor
  • 61
  • 1
  • 8
  • What's `veckaList`? – blhsing Sep 18 '19 at 15:51
  • Looks like `veckaList` should be `wList`. – Barmar Sep 18 '19 at 15:52
  • complete your code snippet please, ex. list cannot be a variable name... example data for component and list would also be very helpful! – droebi Sep 18 '19 at 15:53
  • Sorry, I've edited the post now. I've searched for extend but I am not sure if it is the right thing – L Minor Sep 18 '19 at 15:54
  • Can you show the original list and the desired result? – Barmar Sep 18 '19 at 15:54
  • Is `Wstart == currentWeek` a copying error or in the original code? It should be `=` to assign the variable. – Barmar Sep 18 '19 at 15:57
  • `for component in list:` - what is `list`? I doubt you want to iterate over the type... – Tomerikoo Sep 18 '19 at 15:59
  • 1
    If you search in your browser for "Python list handling", you'll find references that can explain this much better than we can manage here. Overall, I suggest that you work through a tutorial on working with lists. – Prune Sep 18 '19 at 16:11

1 Answers1

0

Do you have a variable called "list" that you are not showing in your code? Because the for loop won't even begin if you try to go through the list variable. Also veckaList isn't defined anywhere, so that should also cause an error.

Post a more complete code to get better answers.

as for adding a list to a list

list1 = [1,2,3,4,5]
list2 = []

list2.append(list1)

>list2
>[[1,2,3,4,5]]
en_lorithai
  • 1,120
  • 7
  • 13