Searching for uniqness in a list of data

Claudio Grondi claudio.grondi at freenet.de
Wed Mar 1 17:04:50 CET 2006

```rh0dium wrote:
> Hi all,
>
> I am having a bit of difficulty in figuring out an efficient way to
> split up my data and identify the unique pieces of it.
>
> list=['1p2m_3.3-1.8v_sal_ms','1p2m_3.3-1.8_sal_log']
>
> Now I want to split each item up on the "_" and compare it with all
> others on the list, if there is a difference I want to create a list of
> the possible choices, and ask the user which choice of the list they
> want.  I have the questioning part under control.   I can't seem to get
> my hands around the logic - the list could be 2 items or 100 long.  The
> point of this is that I am trying to narrow a decision down for an end
> user.  In other words the end user needs to select one of the list
> items, and by breaking it down for them I hope to simplify this.
>
> list=['1p2m_3.3-1.8v_sal_ms','1p6m_3.3-1.8_sal_log']
>  would only question the first data set ['1p2m', '1p6m' ]
>
> list=['1p2m_3.3-1.8v_sal_ms','1p2m_3.3-1.8v_pol_ms','1p3m_3.3-18.v_sal_ms']
>  If on the list ['1p2m','1p2m','1p3m'] the user selected 1p2m then the
> next list would only be ['sal','pol']
>  but if the user initially only selected 1p3m they would be done..
>
> I hope this clarifies what I am trying to do.  I just can't seem to get
> my hands around this - so an explaination of logic would really be
> helpfull.  I picture a 2d list but I can't seem to get it..
>
<code>
list=['1p2m_3.3-1.8v_sal_ms','1p2m_3.3-1.8v_pol_ms','1p3m_3.3-18.v_sal_ms']
dictQlevel_1={}
dictQlevel_2={}
dictQlevel_3={}
for item in list:
splitted = item.split('_')
dictQlevel_1[splitted[0]] = True
dictQlevel_2[splitted[1]] = True
dictQlevel_3[splitted[2]] = True

print 'choose one of: '
for key_1 in dictQlevel_1.keys():
print key_1
print
usrInput = raw_input()

if usrInput == '':
print 'choose one of: '
for key_1 in dictQlevel_1.keys():
for key_2 in dictQlevel_2.keys():
print key_1, key_2
print
usrInput = raw_input()
else:
pass
# or do something

# etc.
</code>

Hope it is what you are looking for.

Claudio

```