I have a file in which multiple columns are presented. I need information of the first column, split that information by delimiter "_", the column is constructed like this: mappinginformation_ACTGTC_AGCGTG.
Furthermore, I want to store ACTGTC in an apart list (UMI list) and the AGCGTG in a list (barcode list).
I did manage to do it for the UMIlist but not the barcodelist yet.
UMIlist = []
for line in linelist:
UMIlist.append(line[0].split("_")[1])
Related
I have a filter to get the contents of a column in another spreadsheet and I want to narrow the list by the contents of another column, which is done by
=FILTER(MasterList!$A$2:A,(MasterList!$E$2:E = "TL"))
But column E may have in the cell the TL value alone or may be combined with other values such as "TL SC AD" of "TL AD" etc in any order and combination. In short, I need to look for CONTAINS "TL"
this is what you need:
=FILTER(MasterList!A2:A, REGEXMATCH(MasterList!E2:E, "TL"))
for more attributes you can do:
=FILTER(MasterList!A2:A, REGEXMATCH(MasterList!E2:E, "TL|XXX|AAA"))
and to make it case insensitive do:
=FILTER(MasterList!A2:A, REGEXMATCH(UPPER(MasterList!E2:E), "TL|XXX"))
or:
=FILTER(MasterList!A2:A, REGEXMATCH(LOWER(MasterList!E2:E), "tl|aaa"))
I'm quite new in python coding and I canĀ“t solve the following problem:
I have a list with trackingpoints for different animals(ID,date,time,lat,lon) given in strings:
aList = [[id,date,time,lat,lon],
[id2,date,time,lat,lon],
[...]]
The txt file is very big and the IDs(a unique animal) is occuring multiple times:
i.e:
aList = [['25','20-05-13','15:16:17','34.89932','24.09421'],
['24','20-05-13','15:16:18','35.89932','23.09421],
['25','20-05-13','15:18:15','34.89932','24.13421'],
[...]]
What I'm trying to do is order the ID's in dictionaries so each unique ID will be the key and all the dates, times, latitudes and longitudes will be the values. Then I would like to write each individual ID to a new txt file so all the values for a specific ID are in one txt file. The output should look like this:
{'25':['20-05-13','15:16:17','34.89932','24.09421'],
['20-05-13','15:18:15','34.89932','24.13421'],
[...],
'24':['20-05-13','15:16:18','35.89932','23.09421'],
[...]
}
I have tried the following (and a lot of other solutions which didn't work):
items = {}
for line in aList:
key,value = lines[0],lines[1:]
items[key] = value
Which results in a key with the last value in the list forthat particular key :
{'25':['20-05-13','15:18:15','34.89932','24.13421'],
'24':['20-05-13','15:16:18','35.89932','23.09421']}
How can I loop through my list and assign the same IDs to the same key and all the corresponding values?
Is there any simple solution to this? Other "easier to implement" solutions are welcome!
I hope it makes sense :)
Try adding all the lists that match to the same ID as list of lists:
aList = [['25','20-05-13','15:16:17','34.89932','24.09421'],
['24','20-05-13','15:16:18','35.89932','23.09421'],
['25','20-05-13','15:18:15','34.89932','24.13421'],
]
items = {}
for line in aList:
key,value = line[0],line[1:]
if key in items:
items[key].append(value)
else:
items[key] = [value]
print items
OUTPUT:
{'24': [['20-05-13', '15:16:18', '35.89932', '23.09421']], '25': [['20-05-13', '15:16:17', '34.89932', '24.09421'], ['20-05-13', '15:18:15', '34.89932', '24.13421']]}
I am struggling on creating a formula with Power Bi that would split a single rows value into a list of values that i want.
So I have a column that is called ID and it has values such as:
"ID001122, ID223344" or "IRRELEVANT TEXT ID112233, MORE IRRELEVANT;ID223344 TEXT"
What is important is to save the ID and 6 numbers after it. The first example would turn into a list like this: {"ID001122","ID223344"}. The second example would look exactly the same but it would just parse all the irrelevant text from between.
I was looking for some type of an loop formula where you could use the text find function to find ID starting point and use middle function to extract 8 characters from the start but I had no progress in finding such. I tried making lists from comma separator but I noticed that not all rows had commas to separate IDs.
The end results would be that the original value is on one column next to the list of parsed values which then could be expanded to new rows.
ID Parsed ID
"Random ID123456, Text;ID23456" List {"ID123456","ID23456"}
Any of you have former experience?
Hey I found the answer by myself using a good article similar to my problem.
Here is my solution without any further text parsing which i can do later on.
each let
PosList = Text.PositionOf([ID],"ID",Occurrence.All),
List = List.Transform(PosList, (x) => Text.Middle([ID],x,8))
in List
For example this would result "(ID343137,ID352973) ID358388" into {ID343137,ID352973,ID358388}
Ended up being easier than I thought. Suppose the solution relied again on the lists!
I want to write a program which will read in a list of tuples, and in the tuple it will contain two elements. The first element can be an Object, and the second element will be the quantity of that Object. Just like: Mylist([{Object1,Numbers},{Object2, Numbers}]).
Then I want to read in the Numbers and print the related Object Numbers times and then store them in a list.
So if Mylist([{lol, 3},{lmao, 2}]), then I should get [lol, lol, lol, lmao, lmao] as the final result.
My thought is to first unzip those tuples (imagine if there are more than 2) into two tuples which the first one contains the Objects while the second one contains the quantity numbers.
After that read the numbers in second tuples and then print the related Object in first tuple with the exact times. But I don't know how to do this. THanks for any help!
A list comprehension can do that:
lists:flatten([lists:duplicate(N,A) || {A, N} <- L]).
If you really want printing too, use recursion:
p([]) -> [];
p([{A,N}|T]) ->
FmtString = string:join(lists:duplicate(N,"~p"), " ")++"\n",
D = lists:duplicate(N,A),
io:format(FmtString, D),
D++p(T).
This code creates a format string for io:format/2 using lists:duplicate/2 to replicate the "~p" format specifier N times, joins them with a space with string:join/2, and adds a newline. It then uses lists:duplicate/2 again to get a list of N copies of A, prints those N items using the format string, and then combines the list with the result of a recursive call to create the function result.
I have:
row1 = [1,'a']
row2 = [2,'b']
I want to create 'allrows' to look like these two rows concatenated together. In fact, I want to start with an empty list and add rows.
append does not do the job, it just creates a long horizontal list.
How do I create a list or other structure that holds each row as a ROW?
For two rows, I want the result to be:
[[1,'a']
[2,'b']]
I am not sure I need the outer brackets, but put them in there assuming the final structure was itself a list, I suppose any other structure that holds these lists, like an "array" of lists, will be fine, as long as I can write out specific rows using:
for line in allrows:
print line
Thanks!
I'm guesing that you code in Python.
List can hold other lists so you can do this
allrows = [row1, row2]
for row in allrows:
print (row)
Output would be
[1,'a']
[2,'b']