python_lists
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revisionLast revisionBoth sides next revision | ||
python_lists [2021/07/23 21:27] – created raju | python_lists [2023/11/07 21:46] – [read file as list of strings] admin | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ===== dummy ===== | ||
==== tasks ==== | ==== tasks ==== | ||
+ | * [[check if two lists are equal]] | ||
* [[get unique items in a list]] | * [[get unique items in a list]] | ||
+ | * [[convert a string to a list]] | ||
+ | ==== search one list in another ==== | ||
+ | < | ||
+ | >>> | ||
+ | >>> | ||
+ | [' | ||
+ | >>> | ||
+ | >>> | ||
+ | [' | ||
+ | >>> | ||
+ | >>> | ||
+ | [10, 0, 12, 0, 17, 0, 9, 20] | ||
+ | >>> | ||
+ | >>> | ||
+ | [' | ||
+ | </ | ||
+ | |||
+ | ==== read file as list of strings ==== | ||
+ | < | ||
+ | fname = " | ||
+ | with open(fname, " | ||
+ | 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 " | ||
+ | >>> | ||
+ | True | ||
+ | >>> | ||
+ | False | ||
+ | </ | ||
python_lists.txt · Last modified: 2023/11/07 21:51 by admin