473,320 Members | 1,858 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

check if the values are prensent in a list of values

Hello All,

I will appreciate the help from the more skillfull pythonistas..

I have a small app that generates a sequence like

00341
01741
03254

This values I am putting in a list.

So I have a list = [00341,01741,03254]

after the programs find the sequence 03401 this sequence is "new" so
it appends on the list. But I want to avoid that as the values are
already on the first sequence of the list (00341).
If I try to use a "in" statement it will give false. as 00341 is
different from 00341 (but for my goal not..)
How can I check against this list and avoid to put "different"
sequences but same values?

as 34100 --dont append on the list
14300 ---dont append on the list
05321 --append to the list.

Am I doing some conceptual error using lists?
There is a better approach?

Thanks

Sep 9 '08 #1
3 1594
flit wrote:
Hello All,

I will appreciate the help from the more skillfull pythonistas..

I have a small app that generates a sequence like

00341
01741
03254
Consider using a dict with sorted tuple keys, eg

d = {}

for seq in ['00341','01741','03254']:
ky = list(seq)
ky.sort()
d[tuple(ky)] = None
then d.keys() are the unique combinations.

HTH,

Emile
>
This values I am putting in a list.

So I have a list = [00341,01741,03254]

after the programs find the sequence 03401 this sequence is "new" so
it appends on the list. But I want to avoid that as the values are
already on the first sequence of the list (00341).
If I try to use a "in" statement it will give false. as 00341 is
different from 00341 (but for my goal not..)
How can I check against this list and avoid to put "different"
sequences but same values?

as 34100 --dont append on the list
14300 ---dont append on the list
05321 --append to the list.

Am I doing some conceptual error using lists?
There is a better approach?

Thanks

--
http://mail.python.org/mailman/listinfo/python-list
Sep 9 '08 #2
Emile van Sebille wrote:
flit wrote:
>Hello All,

I will appreciate the help from the more skillfull pythonistas..

I have a small app that generates a sequence like

00341
01741
03254

Consider using a dict with sorted tuple keys, eg

d = {}

for seq in ['00341','01741','03254']:
ky = list(seq)
ky.sort()
d[tuple(ky)] = None
then d.keys() are the unique combinations.

HTH,

Emile
I'm not judging whether this is a good solution or not, but that's a
silly use of a dict. A set would be better.

s = set()
for seq in ['00341','01741','03254']:
s.add(tuple(sorted(ky)))

Then you just, well, access the set directly, instead of using d.keys()
or something.

(I also replaced the sorting with the sorted() function for brevity.
This all assumes you have at least Python 2.4...)
>This values I am putting in a list.

So I have a list = [00341,01741,03254]

after the programs find the sequence 03401 this sequence is "new" so
it appends on the list. But I want to avoid that as the values are
already on the first sequence of the list (00341).
If I try to use a "in" statement it will give false. as 00341 is
different from 00341 (but for my goal not..)
How can I check against this list and avoid to put "different"
sequences but same values?

as 34100 --dont append on the list
14300 ---dont append on the list
05321 --append to the list.

Am I doing some conceptual error using lists?
There is a better approach?

Thanks
--
Sep 9 '08 #3
On 9 set, 15:13, Bruno Desthuilliers
<bdesth.quelquech...@free.quelquepart.frwrote:
Matt Nordhoff a écrit :
(snip)
I'm not judging whether this is a good solution or not, but that's a
silly use of a dict.

Yeps, but a somewhat common one in code predating the apparition of sets
as builtin type.
Thanks for all contributions, sure I learn a lot with all samples.
Very good thread and answers.

Thank you all
Sep 9 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Adrian Parker | last post by:
I have a PHP generated page which displays X many records. Each record has a checkbox preceding it. The user checks several checkboxes, and hits a delete button. All the corresponding records...
0
by: Alex82 | last post by:
I can't use it....for example i have to create a column that accept values between 1 to 120...i can't enumerate all of them....or i have to accept a value different from NULL if an other column has...
1
by: GIMME | last post by:
If I have : <input name="a1" value="1"> <input name="a2" value="3"> <input name="a3" value="2"> And I want the user to enter the values 1,2, and 3 but not necessarily in that order .... (The...
4
by: Jared | last post by:
Radio Button or Check Box and Event Procedures I need to insert either radio buttons or check boxes onto my form. I'm not sure which to use, or if there are other options. I am using the buttons...
5
by: =?Utf-8?B?QnJlbmRlbiBCaXhsZXI=?= | last post by:
Hello. I am reading a value from a table and trying to determine if that value exists in a list of values associated with a dropdownlist. If so, I select the value, otherwise, I don't. I haven't...
4
by: giftson.john | last post by:
Hi, I am creating an application which migrates all documents from one repository to another repository. Before migration i have to verify all the documents are unique. No duplicates has to be...
5
by: Andrew Meador | last post by:
I have a form (Change Card List by Status) with a check box (cboNOT) and a list box (lstStatus). There is an Open Report button that opens a report (Report - Change Card List) which uses a query...
17
by: wswilson | last post by:
In python, I could write: a = 1 if a in : do something... In c (and many other languages):
6
by: dudeja.rajat | last post by:
Hi, How to check if something is a list or a dictionary or just a string? Eg: for item in self.__libVerDict.itervalues(): self.cbAnalysisLibVersion(END, item) where __libVerDict is a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.