This is terribly ugly:
psData = [] nsData = [] msData = [] ckData = [] mAData = [] RData = [] pData = []
Is there a way to declare these variables on a single line?
In python, we can use the + operator to merge the contents of two lists into a new list. For example, We can use + operator to merge two lists i.e. It returned a new concatenated lists, which contains the contents of both list_1 and list_2.
To initialize a list in Python assign one with square brackets, initialize with the list() function, create an empty list with multiplication, or use a list comprehension. The most common way to declare a list in Python is to use square brackets.
Method #1: Using islice to split a list into sublists of given length, is the most elegant way. # into sublists of given length. Method #2: Using zip is another way to split a list into sublists of given length.
alist, blist, clist, dlist, elist = ([] for i in range(5))
The downside of above approach is, you need to count the number of names on the left of =
and have exactly the same number of empty lists (e.g. via the range
call, or more explicitly) on the right hand side.
The main thing is, don't use something like
alist, blist, clist, dlist, elist = [[]] * 5
nor
alist = blist = clist = dlist = elist = []
which would make all names refer to the same empty list!
psData,nsData,msData,ckData,mAData,RData,pData = [],[],[],[],[],[],[]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With