Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
So I have a list of chars like
nodeList = ['A','C','E','G']
and I want to extract the A. So I found the list[number] method for extracting from a list. But when I put
node = nodeList[0]
I get an error saying that "'dict_keys' object does not support indexing." So how can I work around this? Thanks.
As stated in the comments, nodeList is not actually a list, but a dict_keys object. Before trying to index it, you may simply convert it to a list:
nodeList = list(nodeList)
node = nodeList[0]
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
I used dictionaries the first time and I can't figure out how to get all first elements of a dictionary. The picture shows an example of my problem. I want to get the brand names, not "brand0, brand1" etc.
thisdict = {
"brand0": ("Ford", "green_car"),
"brand1": ("Audi", "yellow_car"),
"brand2": ("Porsche", "red_car")
}
You can use several aproaches to this problem but the easiest is probably this
firstItems = [value[0] for value in thisdict.values()]
this works the same as
firstItems = []
for value in thisdict.values():
firstItems.append(value[0])
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
In python, I wrote a program to compare two strings.
The coedes are below
d = data.iloc[0]
cmpdate = d['quant_date']
print(cmpdate)
if (cmpdate=='2010-03-18'):
print("=================", dt)
else:
print("xxxxxxxxxxxxx", cmpdate)
the results are
2010-03-18
xxxxxxxxxxxxx 2010-03-18
tow strings are exactly same.
what is the problem?
TIA
Make sure you convert both of the dates to datetime format
and check the result
use to_datetime() function
This works fine
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I have following 2D array
name_list = [['Orange', '5'],['Mango','6'],['Banana','3']]
I want to get each fruit name alone with its count and print it using a python code. So how do I read above array to extract the data (inside for loop)
I need print out as
Name:Orange<br/>
Count:5<br/>
Name:Mango<br/>
Count:6<br/>
Name:Banana<br/>
Count:3<br/>
You can unpack your list like this:
for name, amount in name_list:
print("Name:{}".format(name))
print("Count:{}".format(amount))
Try this:
name_list = [['Orange', '5'],['Mango','6'],['Banana','3']]
for item in name_list:
print("Name: {}".format(item[0]))
print("Count: {}".format(item[1]))
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I have a dict as follows:
replace={'/':',',':':','}
Now when I execute the below code
for key in replace:
print(Value)
it gives the following output,
>>:
>>:
I am using Python 3.5.2 and I am also new to using dicts. I expected the output to be
>>,
>>,
What am I doing wrong here ?
Please help.
for value in replacements.values():
print(value)
This is a way to get value for a given key in Python:
replacements={'/':',',':':','}
for key in replacements:
print(replacements[key])
You should do this instead:
for k in replacements:
print(replacements[k])
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I have a .txt file that has a really long RNAm sequence. I don´t know the exact length of the sequence.
What I need to do is extract the part of the sequence that is valid, meaning it starts with "AUG" and ends in "UAA" "UAG" or "UGA". Since the sequence is too long I don´t know the index of any of the letters or where the valid sequence is.
I need to save the new sequence in another variable.
Essentially, what you need to do, without coding the whole thing for you, is:
Example string:
rnaSequence = 'ACGUAFBHUAUAUAGAAAAUGGAGAGAGAAAAUUUGGGGGGGAAAAAAUAAAAAGGGUAUAUAGAUGAGAGAGA'
You will want to find the index of the 'AUG' and the index of 'UAA', 'UAG', or 'UGA' .. Something like this
rnaStart = rnaSequence.index(begin)
Then you'll need to set the slice of the string to a new variable
rnaSubstring = rnaSequence[rnaStart:rnaEnd+3]
Which in my string above, returns:
AUGGAGAGAGAAAAUUUGGGGGGGAAAAAAUAA