coveralls: 
[![Coverage Status](https://coveralls.io/builds/31851646/badge)](https://coveralls.io/builds/31851646)

Coverage increased (+0.05%) to 89.855% when pulling **1e99042e5523d97823f1091ae98d5a4badbc2c51 on bbc2:fix-empty-expanded-value-duplicate-key** into **e4bbb8a2aa881409af6fb92933c18e2af6609da8 on theskumar:master**.

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 116d97f..a01d3dc 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,7 +7,9 @@ project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
 
 ## [Unreleased]
 
-*No unreleased change at this time.*
+### Fixed
+
+- Fix potentially empty expanded value for duplicate key (#260 by [@bbc]).
 
 ## [0.14.0] - 2020-07-03
 
diff --git a/src/dotenv/main.py b/src/dotenv/main.py
index 8f77e83..607299a 100644
--- a/src/dotenv/main.py
+++ b/src/dotenv/main.py
@@ -18,7 +18,7 @@ logger = logging.getLogger(__name__)
 
 if IS_TYPE_CHECKING:
     from typing import (
-        Dict, Iterator, Match, Optional, Pattern, Union, Text, IO, Tuple
+        Dict, Iterable, Iterator, Match, Optional, Pattern, Union, Text, IO, Tuple
     )
     if sys.version_info >= (3, 6):
         _PathLike = os.PathLike
@@ -83,9 +83,13 @@ class DotEnv():
         if self._dict:
             return self._dict
 
-        values = OrderedDict(self.parse())
-        self._dict = resolve_nested_variables(values) if self.interpolate else values
-        return self._dict
+        if self.interpolate:
+            values = resolve_nested_variables(self.parse())
+        else:
+            values = OrderedDict(self.parse())
+
+        self._dict = values
+        return values
 
     def parse(self):
         # type: () -> Iterator[Tuple[Text, Optional[Text]]]
@@ -211,7 +215,7 @@ def unset_key(dotenv_path, key_to_unset, quote_mode="always"):
 
 
 def resolve_nested_variables(values):
-    # type: (Dict[Text, Optional[Text]]) -> Dict[Text, Optional[Text]]
+    # type: (Iterable[Tuple[Text, Optional[Text]]]) -> Dict[Text, Optional[Text]]
     def _replacement(name, default):
         # type: (Text, Optional[Text]) -> Text
         default = default if default is not None else ""
@@ -229,7 +233,7 @@ def resolve_nested_variables(values):
 
     new_values = {}
 
-    for k, v in values.items():
+    for (k, v) in values:
         new_values[k] = __posix_variable.sub(_re_sub_callback, v) if v is not None else None
 
     return new_values

Unexpected Behavior when Parsing Duplicate Key
Hello. I started using this package yesterday and I am sorry if I am missing something simple.
I am trying to read an env file that looks like this:
```
export hello=hi
export greetings=${hello}
export goodbye=bye
export greetings=${goodbye}
```
 To read it, I wrote the following small program:
```python
import os
import dotenv
from pathlib import Path

env_path = './test.env'
dotenv.load_dotenv(dotenv_path=env_path,verbose=True)
print(os.getenv('greetings'))
```
When I run this program, it outputs a single empty line. This happens even when I set override to True. I was expecting the program to output 'bye'. Is this a bug or the expected behavior for handling duplicate keys ? I am currently running 3.7.3 and python-dotenv version 0.10.3. Thank you. 
diff --git a/tests/test_main.py b/tests/test_main.py
index 3a3d059..339d00b 100644
--- a/tests/test_main.py
+++ b/tests/test_main.py
@@ -337,6 +337,8 @@ def test_dotenv_values_file(dotenv_file):
 
         # Re-defined and used in file
         ({"b": "c"}, "b=d\na=${b}", True, {"a": "d", "b": "d"}),
+        ({}, "a=b\na=c\nd=${a}", True, {"a": "c", "d": "c"}),
+        ({}, "a=b\nc=${a}\nd=e\nc=${d}", True, {"a": "b", "c": "e", "d": "e"}),
     ],
 )
 def test_dotenv_values_stream(env, string, interpolate, expected):

pip install -e .[cli]
parse_log_pytest
requirements.txt
pytest
3.6
requirements.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
attrs==22.2.0
backcall==0.2.0
bleach==4.1.0
bump2version==1.0.1
bumpversion==0.6.0
certifi==2021.5.30
cffi==1.15.1
charset-normalizer==2.0.12
click==8.0.4
colorama==0.4.5
coverage==6.2
cryptography==40.0.2
dataclasses==0.7
decorator==5.1.1
distlib==0.3.9
docstring-parser==0.7.3
docutils==0.18.1
falcon==2.0.0
filelock==3.4.1
flake8==5.0.4
ghp-import==2.1.0
gitdb==4.0.9
GitPython==3.1.18
hug==2.6.1
idna==3.10
importlib-metadata==4.2.0
importlib-resources==5.4.0
iniconfig==1.1.1
ipython==7.16.3
ipython-genutils==0.2.0
jedi==0.17.2
jeepney==0.7.1
Jinja2==3.0.3
keyring==23.4.1
livereload==2.6.3
Mako==1.1.6
Markdown==3.3.4
MarkupSafe==2.0.1
mccabe==0.7.0
mergedeep==1.3.4
mkdocs==1.2.4
mkdocs-material==7.3.0
mkdocs-material-extensions==1.0.3
mock==5.2.0
packaging==21.3
parso==0.7.1
pdocs==1.1.1
pexpect==4.9.0
pickleshare==0.7.5
pkginfo==1.10.0
platformdirs==2.4.0
pluggy==1.0.0
portray==1.7.0
prompt-toolkit==3.0.36
ptyprocess==0.7.0
py==1.11.0
pycodestyle==2.9.1
pycparser==2.21
pyflakes==2.5.0
Pygments==2.14.0
pymdown-extensions==7.1
pyparsing==3.1.4
pytest==7.0.1
pytest-cov==4.0.0
python-dateutil==2.9.0.post0
-e git+https://github.com/theskumar/python-dotenv.git@e4bbb8a2aa881409af6fb92933c18e2af6609da8#egg=python_dotenv
PyYAML==6.0.1
pyyaml_env_tag==0.1
readme-renderer==34.0
requests==2.27.1
requests-toolbelt==1.0.0
rfc3986==1.5.0
SecretStorage==3.3.3
sh==1.14.3
six==1.17.0
smmap==5.0.0
toml==0.10.2
tomli==1.2.3
tornado==6.1
tox==3.28.0
tqdm==4.64.1
traitlets==4.3.3
twine==3.8.0
typing_extensions==4.1.1
urllib3==1.26.20
virtualenv==20.16.2
watchdog==2.3.1
wcwidth==0.2.13
webencodings==0.5.1
yaspin==0.15.0
zipp==3.6.0

name: python-dotenv
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2021.5.30=py36h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.3=he6710b0_2
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - pip=21.2.2=py36h06a4308_0
  - python=3.6.13=h12debd9_1
  - readline=8.2=h5eee18b_0
  - setuptools=58.0.4=py36h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - wheel=0.37.1=pyhd3eb1b0_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - attrs==22.2.0
      - backcall==0.2.0
      - bleach==4.1.0
      - bump2version==1.0.1
      - bumpversion==0.6.0
      - cffi==1.15.1
      - charset-normalizer==2.0.12
      - click==8.0.4
      - colorama==0.4.5
      - coverage==6.2
      - cryptography==40.0.2
      - dataclasses==0.7
      - decorator==5.1.1
      - distlib==0.3.9
      - docstring-parser==0.7.3
      - docutils==0.18.1
      - falcon==2.0.0
      - filelock==3.4.1
      - flake8==5.0.4
      - ghp-import==2.1.0
      - gitdb==4.0.9
      - gitpython==3.1.18
      - hug==2.6.1
      - idna==3.10
      - importlib-metadata==4.2.0
      - importlib-resources==5.4.0
      - iniconfig==1.1.1
      - ipython==7.16.3
      - ipython-genutils==0.2.0
      - jedi==0.17.2
      - jeepney==0.7.1
      - jinja2==3.0.3
      - keyring==23.4.1
      - livereload==2.6.3
      - mako==1.1.6
      - markdown==3.3.4
      - markupsafe==2.0.1
      - mccabe==0.7.0
      - mergedeep==1.3.4
      - mkdocs==1.2.4
      - mkdocs-material==7.3.0
      - mkdocs-material-extensions==1.0.3
      - mock==5.2.0
      - packaging==21.3
      - parso==0.7.1
      - pdocs==1.1.1
      - pexpect==4.9.0
      - pickleshare==0.7.5
      - pkginfo==1.10.0
      - platformdirs==2.4.0
      - pluggy==1.0.0
      - portray==1.7.0
      - prompt-toolkit==3.0.36
      - ptyprocess==0.7.0
      - py==1.11.0
      - pycodestyle==2.9.1
      - pycparser==2.21
      - pyflakes==2.5.0
      - pygments==2.14.0
      - pymdown-extensions==7.1
      - pyparsing==3.1.4
      - pytest==7.0.1
      - pytest-cov==4.0.0
      - python-dateutil==2.9.0.post0
      - pyyaml==6.0.1
      - pyyaml-env-tag==0.1
      - readme-renderer==34.0
      - requests==2.27.1
      - requests-toolbelt==1.0.0
      - rfc3986==1.5.0
      - secretstorage==3.3.3
      - sh==1.14.3
      - six==1.17.0
      - smmap==5.0.0
      - toml==0.10.2
      - tomli==1.2.3
      - tornado==6.1
      - tox==3.28.0
      - tqdm==4.64.1
      - traitlets==4.3.3
      - twine==3.8.0
      - typing-extensions==4.1.1
      - urllib3==1.26.20
      - virtualenv==20.16.2
      - watchdog==2.3.1
      - wcwidth==0.2.13
      - webencodings==0.5.1
      - yaspin==0.15.0
      - zipp==3.6.0
prefix: /opt/conda/envs/python-dotenv

tests/test_main.py::test_dotenv_values_stream[env19-a=b\nc=${a}\nd=e\nc=${d}-True-expected19]
tests/test_main.py::test_set_key_permission_error
tests/test_main.py::test_set_key_no_file tests/test_main.py::test_set_key[-a--expected0-a=""\n] tests/test_main.py::test_set_key[-a-b-expected1-a="b"\n] tests/test_main.py::test_set_key[-a-'b'-expected2-a="b"\n] tests/test_main.py::test_set_key[-a-"b"-expected3-a="b"\n] tests/test_main.py::test_set_key[-a-b'c-expected4-a="b'c"\n] tests/test_main.py::test_set_key[-a-b"c-expected5-a="b\\"c"\n] tests/test_main.py::test_set_key[a=b-a-c-expected6-a="c"\n] tests/test_main.py::test_set_key[a=b\n-a-c-expected7-a="c"\n] tests/test_main.py::test_set_key[a=b\n\n-a-c-expected8-a="c"\n\n] tests/test_main.py::test_set_key[a=b\nc=d-a-e-expected9-a="e"\nc=d] tests/test_main.py::test_set_key[a=b\nc=d\ne=f-c-g-expected10-a=b\nc="g"\ne=f] tests/test_main.py::test_set_key[a=b\n-c-d-expected11-a=b\nc="d"\n] tests/test_main.py::test_get_key_no_file tests/test_main.py::test_get_key_not_found tests/test_main.py::test_get_key_ok tests/test_main.py::test_get_key_none tests/test_main.py::test_unset_with_value tests/test_main.py::test_unset_no_value tests/test_main.py::test_unset_non_existent_file tests/test_main.py::test_find_dotenv_no_file_raise tests/test_main.py::test_find_dotenv_no_file_no_raise tests/test_main.py::test_find_dotenv_found tests/test_main.py::test_load_dotenv_existing_file tests/test_main.py::test_load_dotenv_no_file_verbose tests/test_main.py::test_load_dotenv_existing_variable_no_override tests/test_main.py::test_load_dotenv_existing_variable_override tests/test_main.py::test_load_dotenv_utf_8 tests/test_main.py::test_load_dotenv_in_current_dir tests/test_main.py::test_dotenv_values_file tests/test_main.py::test_dotenv_values_stream[env0-a=$b-False-expected0] tests/test_main.py::test_dotenv_values_stream[env1-a=$b-True-expected1] tests/test_main.py::test_dotenv_values_stream[env2-a=${b}-False-expected2] tests/test_main.py::test_dotenv_values_stream[env3-a=${b}-True-expected3] tests/test_main.py::test_dotenv_values_stream[env4-a=${b:-d}-False-expected4] tests/test_main.py::test_dotenv_values_stream[env5-a=${b:-d}-True-expected5] tests/test_main.py::test_dotenv_values_stream[env6-b=c\na=${b}-True-expected6] tests/test_main.py::test_dotenv_values_stream[env7-a=${b}-True-expected7] tests/test_main.py::test_dotenv_values_stream[env8-a=${b:-d}-True-expected8] tests/test_main.py::test_dotenv_values_stream[env9-a="${b}"-True-expected9] tests/test_main.py::test_dotenv_values_stream[env10-a='${b}'-True-expected10] tests/test_main.py::test_dotenv_values_stream[env11-a=x${b}y-True-expected11] tests/test_main.py::test_dotenv_values_stream[env12-a=${a}-True-expected12] tests/test_main.py::test_dotenv_values_stream[env13-a=${a}-True-expected13] tests/test_main.py::test_dotenv_values_stream[env14-a=${a:-c}-True-expected14] tests/test_main.py::test_dotenv_values_stream[env15-a=${a:-c}-True-expected15] tests/test_main.py::test_dotenv_values_stream[env16-a=${b}${b}-True-expected16] tests/test_main.py::test_dotenv_values_stream[env17-b=d\na=${b}-True-expected17] tests/test_main.py::test_dotenv_values_stream[env18-a=b\na=c\nd=${a}-True-expected18]
src/dotenv/main.py CHANGELOG.md
src/dotenv/main.py CHANGELOG.md