d = {'AVNIVGYSNAQGVDY': [ID[123431],Frequency[27.0],Assay['Tetramer']], 'DIKYTWNVPKI': [ID[887473],Frequency[50.0],Assay['3H']], 'LRQMRTVTPIRMQGG': [ID[34234],Frequency[11.9],Assay['Elispot']]}
I am working with lists since my actual file is bigger and I will append more values to those lists.
Answer
First, do you know about the csv module? If not, read the introduction and examples to the point where you know how to get an iterable of rows. Print each one out, and they'll look something like this:
But you don't want a list of lists, or a list of dictionaries; you want a dictionary of lists, where each key is the Epitope from a row, and the corresponding value is the other three values, right? So… just insert each row into a dictionary that way:
d = {}
with open(path, 'rb') as f:with csv.DictReader(f) as reader:for row in reader:d[row['Epitope']] = [row['ID'], row['Frequency'], row['Assay']]
(This would be more compact with a plain reader instead of a DictReader, but I think it's more readable this way if you come back to the code a few months from now.)
You also want to convert the values and use them as keys for another lookup, but that should be trivial. For example:
Closed. This question needs details or clarity. It is not currently accepting answers.Want to improve this question? Add details and clarify the problem by editing this post.Closed 9 years ago.Improve…
I want to open a text file containing a column of words and create a list or, alternatively, a string containing these words.
Why do I get this error:
>>> with open(some_file.txt, r) as some_f…
I have to read an Excel file Using python. By the time I use xl = pd.ExcelFile("abc.xlsx")The column values which had hyperlink assigned to it becomes a simple number without any hyperlink.Is…
say user gives a number n=3
then I have to create 3 files dynamically. How will I do that? What can be the names of those files. Specifically I want n number of .jpg file created.
I have created an empty 2D array. When I try to add stuff inside of it, it doesnt do so properly. Each index contains the appropriate info, but for some reason, carries the info from the previous into …
I need to merge strings together to create one string. For example the strings for "hello" that need to be combined are:
[H----], [-E---], [--LL-], and [----O]This is the current code I have …
I have been having issues with the code I am trying to right with the model I am trying to code the following error has appeared and being a relative novice I am unsure of how to resolve it.ValueError …
I should find a hello word in a string, which I gave it from input.
Here is the code that I currently have, but I cannot match hello with the character list.mylist = it can be any letter plus hello in …
Im trying to write a programme to get all permutations of a string of letter using recursion. As Im a beginner in Python, I learnt about recursion with examples like Fibonacci Number and Factorial. I u…