- This topic is empty.
Viewing 1 post (of 1 total)
Viewing 1 post (of 1 total)
- You must be logged in to reply to this topic.
Consider the following two versions of the load_file() method.
Are they functionally the same?
def load_file(self):
names = {}
with open(self.__filename) as f:
for line in f:
name, *numbers = line.strip().split(';')
names[name] = numbers
def load_file(self):
names = {}
with open(self.__filename) as f:
for line in f:
parts = line.strip().split(';')
name, *numbers = parts
names[name] = numbers
name, *numbers = line.strip().split(';')
parts:
parts = line.strip().split(';')
name, *numbers = parts
;name and numbersnames[name] = numbers
They are identical.
Using parts makes debugging easier:
print(parts)
But for clean, concise code, Version 1 is perfectly fine.
