Question: I have a file with questions and answers on the same line, I want to seperate them and append them to their own empty list but keep getting this error:  

`builtins.ValueError: need more than 1 value to unpack`

```
questions_list = []
answers_list = []

questions_file=open('qanda.txt','r')

for line in questions_file:
    line=line.strip()

    questions,answers =line.split(':')

    questions_list.append(questions)
    answers_list.append(answers)

```

Answer: 
This is probably because when you're doing the splitting, there is no `:`, so the function just returns one argument, and not 2. This is probably caused by the last line, meaning that you're last line has nothing but empty spaces. Like so:

```
>>> a = '   '
>>> a = a.strip()
>>> a
''
>>> a.split(':')
['']

```

As you can see, the list returned from `.split` is just a single empty string. So, just to show you a demo, this is a sample file:

> 
> 
> ```
> a: b
> c: d
> e: f
> 
> g: h
> 
> ```
> 
> 

We try to use the following script (`val.txt` is the name of the above file):

```
with open('val.txt', 'r') as v:
    for line in v:
        a, b = line.split(':')
        print a, b

```

And this gives us:

```
Traceback (most recent call last):
a  b

c  d
  File "C:/Nafiul Stuff/Python/testingZone/28_11_13/val.py", line 3, in <module>

    a, b = line.split(':')
e  f
ValueError: need more than 1 value to unpack

```

When trying to look at this through a debugger, the variable `line` becomes `\n`, and you can't split that.

However, a simple logical ammendment, would correct this problem:

```
with open('val.txt', 'r') as v:
    for line in v:
        if ':' in line:
            a, b = line.strip().split(':')
            print a, b

```
The reason why this happens could be a few, as already covered in the other answers. Empty line, or maybe a line only have a question and no colon. If you want to parse the lines even if they don't have the colon (for example if some lines only have the question), you can change your split to the following:

```
questions, answers, garbage = (line+'::').split(':', maxsplit=2)

```

This way, the values for `questions` and `answers` will be filled if they are there, and will be empty it the original file doesn't have them. For all intents and purposes, ignore the variable `garbage`.