0

I know this question has been asked and I have read through them but I still can't get this to work.

I want to do the following:

bigDict={'AABAA':{'00500':4, '00110':1, '00001':1}, 'AAAAA':{'03300':15, '03110':10, '00401':1}, 'BBBBB':{'11500':1, '11110':1, '11111':1}}

the numbers WITHOUT quotes, 4,1,1,15,10,1,1,1,1 are the COUNTS of those strings which are part of the larger string.

Is this possible in python using nested dictionary? Thank you

I use a sliding window move along a string like AAAABBBBBBLLLLLLAAA and once I find the 5 seq length string for example AABAA, I take that and find the corresponding "number" seq '00500', if I encounter another AABAA then I extract the number seq for that, and if that is again 00500, I now increase the counter for 00500 to 2 from 1

7
  • 3
    What exactly are you trying to do? Are you generating this dictionary from the larger string you referenced, generating the larger string from this dictionary, something else? Commented Jan 6, 2014 at 19:48
  • 1
    you could use Counters instead of those inner dicts, but appart from that, I have no idea what you are trying to do. Commented Jan 6, 2014 at 19:51
  • 1
    Yes is it possible. Your snippet is valid and legit python. Commented Jan 6, 2014 at 19:51
  • yes exactly, I use a sliding window move along a string like AAAABBBBBBLLLLLLAAA and once I find the 5 seq length string for example AABAA, I take that and find the corresponding "number" seq '00500', if I encounter another AABAA then I extract the number seq for that, and if that is again 00500, I now increase the counter for 00500 to 2 from 1... Commented Jan 6, 2014 at 19:51
  • I know its valid to have such a structure but I don't know how to create it in python. Commented Jan 6, 2014 at 19:54

1 Answer 1

1
bigDict = {}

then when you have a letter label and number ...

bigDict.setdefault(label, {}).setdefault(num, 0)
bigDict[label][num] += 1
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.