Re: [Tutor] updating a dictionary

2015-02-20 Thread Danny Yoo
On Fri, Feb 20, 2015 at 3:47 PM, Chris Stinemetz wrote: > > I understand what you are explaining to me but I am not sure why every > instance of the key 8:value changes when I assign a new value to it. Ah. Be wary of structure sharing when the values being shared are mutable. A textbook examp

Re: [Tutor] updating a dictionary

2015-02-20 Thread Chris Stinemetz
On Fri, Feb 20, 2015 at 4:51 PM, Mark Lawrence wrote: > On 20/02/2015 17:56, Chris Stinemetz wrote: > > Please don't top post as it makes long threads difficult if not impossible > to follow, thanks. > > I am getting closer. I think I have figured out the logic. I just have a >> quick question.

Re: [Tutor] updating a dictionary

2015-02-20 Thread Mark Lawrence
On 20/02/2015 17:56, Chris Stinemetz wrote: Please don't top post as it makes long threads difficult if not impossible to follow, thanks. I am getting closer. I think I have figured out the logic. I just have a quick question. How do you access key:values in a nested dictionary? MOL02997_C':

Re: [Tutor] updating a dictionary

2015-02-20 Thread Alan Gauld
On 20/02/15 17:56, Chris Stinemetz wrote: I am getting closer. I think I have figured out the logic. I just have a quick question. How do you access key:values in a nested dictionary? MOL02997_C': [{'2': '0', '7': '0', '8': '0', '9': '0'}]} say I want to access the key:value 8:0 print dict['MO

Re: [Tutor] updating a dictionary

2015-02-20 Thread Chris Stinemetz
I am getting closer. I think I have figured out the logic. I just have a quick question. How do you access key:values in a nested dictionary? MOL02997_C': [{'2': '0', '7': '0', '8': '0', '9': '0'}]} say I want to access the key:value 8:0 print dict['MOL02997_C']['8'] doesn't seem to work. Thank

Re: [Tutor] updating a dictionary

2015-02-20 Thread Peter Otten
Chris Stinemetz wrote: > ​Here is a sample of the input data, it is tab delimited and I chopped it > down for example purposes: > ​ > > KSL03502_7A_1 11.5921 > KSL03502_7B_1 46.4997 > KSL03502_7C_1 13.5839 > KSL03505_7A_1 12.8684 > KSL03505_7B_1 16.5311 > KSL03505_7C_1 18.9926 > KSL03509_7A_1 3.

Re: [Tutor] updating a dictionary

2015-02-19 Thread Mark Lawrence
On 20/02/2015 00:55, Chris Stinemetz wrote: Other than the minor tweaks I've suggested I'm not sure what your problem is? I think we need to see the data to understand the issue. ​Here is a sample of the input data, it is tab delimited and I chopped it down for example purposes: ​ KSL03

Re: [Tutor] updating a dictionary

2015-02-19 Thread Chris Stinemetz
> > > > > Other than the minor tweaks I've suggested I'm not sure what your problem > is? I think we need to see the data to understand the issue. ​Here is a sample of the input data, it is tab delimited and I chopped it down for example purposes: ​ KSL03502_7A_1 11.5921 KSL03502_7B_1 46.4997 K

Re: [Tutor] updating a dictionary

2015-02-19 Thread Emile van Sebille
On 2/19/2015 3:10 PM, Alan Gauld wrote: On 19/02/15 22:50, Emile van Sebille wrote: if cell.endswith(suffix, 14, 16) is False: ... so they'll never end with numeric values. Further, "".endswith() accepts only one argument so you ought to get an error on this line. Sorry Emile, The OP

Re: [Tutor] updating a dictionary

2015-02-19 Thread Alan Gauld
On 19/02/15 22:50, Emile van Sebille wrote: if cell.endswith(suffix, 14, 16) is False: ... so they'll never end with numeric values. Further, "".endswith() accepts only one argument so you ought to get an error on this line. Sorry Emile, The OP is correct. ## >>> h

Re: [Tutor] updating a dictionary

2015-02-19 Thread Alan Gauld
On 19/02/15 21:19, Chris Stinemetz wrote: The dictionary format looks like: format = {'Cell': '','7':'','8':'','9':'','2':''} For each line read in I would simply like to check to see if a Cell key;value exists and if it does update the correct key==band(7,8,9,2) within the dictionary. If the

Re: [Tutor] updating a dictionary

2015-02-19 Thread Emile van Sebille
On 2/19/2015 1:19 PM, Chris Stinemetz wrote: Hello List, I have a dictionary that I would like to update/add rows to it as I read a file line by line. The dictionary format looks like: format = {'Cell': '','7':'','8':'','9':'','2':''} For each line read in I would simply like to check to see

[Tutor] updating a dictionary

2015-02-19 Thread Chris Stinemetz
Hello List, I have a dictionary that I would like to update/add rows to it as I read a file line by line. The dictionary format looks like: format = {'Cell': '','7':'','8':'','9':'','2':''} For each line read in I would simply like to check to see if a Cell key;value exists and if it does updat