User Tools

Site Tools


python_lists

This is an old revision of the document!


dummy

tasks

read file as list of strings

fname = "foo.txt"
with open(fname, "r") as fh:
  lines = [line.rstrip() for line in fh]

Check if a variable is a list

% python
Python 3.11.4 (main, Jul  5 2023, 13:45:01) [GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> isinstance(['foo'], list)
True
>>> isinstance('foo', list)
False
python_lists.1696823764.txt.gz · Last modified: 2023/10/09 03:56 by raju