Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #95821 > unrolled thread

How to compare lists

Started by"Jahn" <jana1972@centrum.cz>
First post2015-09-01 07:08 +0200
Last post2015-09-01 10:26 -0700
Articles 3 — 3 participants

Back to article view | Back to comp.lang.python


Contents

  How to compare  lists "Jahn" <jana1972@centrum.cz> - 2015-09-01 07:08 +0200
    Re: How to compare  lists Denis McMahon <denismfmcmahon@gmail.com> - 2015-09-01 11:58 +0000
    Re: How to compare  lists Rustom Mody <rustompmody@gmail.com> - 2015-09-01 10:26 -0700

#95821 — How to compare lists

From"Jahn" <jana1972@centrum.cz>
Date2015-09-01 07:08 +0200
SubjectHow to compare lists
Message-ID<mailman.38.1441092235.23514.python-list@python.org>

1.
How can I save 256 lists, each list has 32 values( hexadecimal numbers)
2.
How to compare the saved lists with another 256 lists ( that are read online and have the 
same structure as the list one)?
( the first list must be saved in the  previous step)

E.g


Thanks

[toc] | [next] | [standalone]


#95828

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2015-09-01 11:58 +0000
Message-ID<ms43ti$tp0$1@dont-email.me>
In reply to#95821
On Tue, 01 Sep 2015 07:08:48 +0200, Jahn wrote:

> 1.
> How can I save 256 lists, each list has 32 values( hexadecimal numbers)
> 2.
> How to compare the saved lists with another 256 lists ( that are read
> online and have the same structure as the list one)?
> ( the first list must be saved in the  previous step)

Develop code that works for smaller lists. Test it. When it works, try it 
on bigger lists.

For example, you seem to have two very separate requirements:

Save (and presumably read) a list. My favourite mechanism for saving data 
structures is json. Read the json module help. Gogling "python store list 
data" might bring you other suggestions.

Comparing two lists. One method is to step through the members of each 
list in turn, and see if it is in the other list. Another method is to 
check that the lists are the same length, and have the same value at each 
element position. Both may have flaws depending on the exact nature of 
your requirement - and what you consider to be identical lists. Googling 
"python compare lists" may lead you to some ideas.

When you have written and tested your code, if it's not doing what you 
expect, you could come back here and post your code with a description of 
what you think it should do, what it actually does, and why you think 
that's wrong, and we'll try and help you fix.

What we won't do is write your application from scratch.

-- 
Denis McMahon, denismfmcmahon@gmail.com

[toc] | [prev] | [next] | [standalone]


#95840

FromRustom Mody <rustompmody@gmail.com>
Date2015-09-01 10:26 -0700
Message-ID<0abed2f9-927e-47b7-ae3a-b13209e415c8@googlegroups.com>
In reply to#95821
On Tuesday, September 1, 2015 at 12:54:08 PM UTC+5:30, Jahn wrote:
> 1.
> How can I save 256 lists, each list has 32 values( hexadecimal numbers)
> 2.
> How to compare the saved lists with another 256 lists ( that are read online and have the 
> same structure as the list one)?
> ( the first list must be saved in the  previous step)

To add to what the others have said/asked:

Many times programmers want sets but they are programmed(!!) to think "Lists!"
This can be because for example
>>> [1,2,3] == [2,1,3]
False
>>> {1,2,3} == {2,1,3}
True
>>> [1,2,3,3] == [1,2,3]
False
>>> {1,2,3,3} == {1,2,3}
True
>>> list(set([1,2,1,3,4,4,]))
[1, 2, 3, 4]

[Though theres no guarantee of the order of the last (that I know) ]

ie you may prefer sets to lists when order and/or repetition dont signify

> 
> E.g

???

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web