Skip to content

Commit 4deffd8

Browse files
authored
Make listToFile more pythonic - "\n".join([])
1 parent 67f0430 commit 4deffd8

1 file changed

Lines changed: 1 addition & 2 deletions

File tree

ListToFile.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#write a list to file
22
color = ['Red', 'Green', 'White', 'Black', 'Pink', 'Yellow']
33
with open('abc.txt', "w") as myfile:
4-
for c in color:
5-
myfile.write("%s\n" % c)
4+
myfile.write("\n".join(color))
65

76
content = open('abc.txt')
87
print(content.read())

0 commit comments

Comments
 (0)