Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python convert file into list

# Saving the list
a = ["apple", "banana", 2, 3]
with open("test.txt", "w") as f:
    for item in a:
        f.write("%s
" % item)

with open("test.txt", "r") as f:
    print(f.read())

# Converting contents of file into new list
f = open("test.txt", "r")
listItems = f.read().splitlines()
print(listItems)
Comment

python file to list

import pandas as pd

def file_to_list(file):
    rtn: object = []
    file_object: object = open(file, "r")
    rtn: object = file_object.read().splitlines()
    file_object.close()
    return list(filter(None, pd.unique(rtn).tolist())) # Remove Empty/Duplicates Values
    pass

# Example #    
data_from_file: object = file_to_list('filename.txt')    
Comment

PREVIOUS NEXT
Code Example
Python :: how to apply logarithm in pandas dataframe 
Python :: remove word from string python 
Python :: how to create progress bar python 
Python :: on_ready discord.py 
Python :: plt plot circle 
Python :: run unittest in terminal python 
Python :: NotImplementedError: Please use HDF reader for matlab v7.3 files 
Python :: python extract specific columns from pandas dataframe 
Python :: brownie to wei 
Python :: django settings variables 
Python :: pandas to_csv append 
Python :: python get current mouse position 
Python :: dataframe to txt 
Python :: types of all columns pandas 
Python :: import excel file to python 
Python :: python join generators 
Python :: xpath beautifulsoup 
Python :: python playsound stop 
Python :: django install whitenoise 
Python :: insta profile downloader in python 
Python :: selenium get current url 
Python :: python os get output 
Python :: zeller year 
Python :: matplotlib latex non italic indices 
Python :: how to find common characters in two strings in python 
Python :: get file extension python 
Python :: how to enable matplotlib in notebook 
Python :: .get python 
Python :: python f string decimal places 
Python :: pandas sort columns by name 
ADD CONTENT
Topic
Content
Source link
Name
5+6 =