Questions tagged [cmp]

cmp is a command line utility for computer systems that use Unix or a Unix-like operating system.It compares two files of any type and writes the results to the standard output

By default, cmp is silent if the files are the same; if they differ, the byte and line number at which the first difference occurred is reported.

Return values:

0 —> files are identical
1 —> files differ
2 —> inaccessible or missing argument

Read more

150 questions
60
votes
1 answer

How does Python's cmp_to_key function work?

I came across this function here. I am baffled as to how this would be implemented -- how does the key function generated by cmp_to_key know what "position" a given element should be without checking how the given element compares with every other…
math4tots
  • 8,540
  • 14
  • 58
  • 95
44
votes
2 answers

Why is the cmp parameter removed from sort/sorted in Python3.0?

from python wiki: In Py3.0, the cmp parameter was removed entirely (as part of a larger effort to simplify and unify the language, eliminating the conflict between rich comparisons and the __cmp__ methods). I do not understand the reasoning why cmp…
brain storm
  • 30,124
  • 69
  • 225
  • 393
31
votes
5 answers

JNZ & CMP Assembly Instructions

Correct me if I am wrong. This is my understanding of JNZ and CMP. JNZ - The jump WILL take place if the Z Flag is NOT zero (1) CMP - If the two values are equal, the Z Flag is set (1) otherwise it is not set (0) This is a flash tutorial I am…
43.52.4D.
  • 950
  • 6
  • 14
  • 28
16
votes
5 answers

Python: 'object in list' checks and '__cmp__' overflow

this is my first time at stack overflow so I'm sorry if the format doesn't fit quite right with the site. I just recently started learning programming, almost 2 weeks have passed since. I'm learning python from…
Ulquiomaru
  • 736
  • 6
  • 9
16
votes
2 answers

TypeError: 'cmp' is an invalid keyword argument for this function

I'm using Python3, but the script is not compatible with this version and I hit some errors. Now I have problem with cmp parameter. Here is the code def my_cmp(x,y): counter = lambda x, items: reduce(lambda a,b:a+b, [list(x).count(xx) for xx in…
ewilulu
  • 193
  • 2
  • 2
  • 7
16
votes
2 answers

x86 CMP Instruction Difference

Question What is the (non-trivial) difference between the following two x86 instructions? 39 /r CMP r/m32,r32 Compare r32 with r/m32 3B /r CMP r32,r/m32 Compare r/m32 with r32 Background I'm building a Java assembler, which will be used…
Pindatjuh
  • 10,550
  • 1
  • 41
  • 68
16
votes
5 answers

Comparison function that compares two text files in Unix

I was wondering if anyone could tell me if there is a function available in unix, bash that compares all of the lines of the files. If they are different it should output true/false, or -1,0,1. I know these cmp functions exist in other languages. I…
Masterminder
  • 1,127
  • 7
  • 21
  • 31
9
votes
3 answers

sort() in Python using cmp

I am trying to sort a list, move all 0 to the end of list. example: [0,1,0,2,3,0,4]->[1,2,3,4,0,0,0] and I see someone code it in 1 line list.sort(cmp=lambda a,b:-1 if b==0 else 0) But I don't understand what inside the parentheses mean. Could…
yoppy
  • 133
  • 1
  • 1
  • 5
7
votes
5 answers

fatal error C1083: Cannot open include file: 'basetsd.h'

So i have been trying to install Scrapy for Python for the last couple of days. Trying anything i could think off and read everything i have come across with similar problems, but haven't been able to find a solution. So here is the code. Thank…
Fony Stark
  • 71
  • 1
  • 1
  • 3
6
votes
4 answers

Sort list of strings alphabetically

So i have a question, how can i sort this list: ['Pera','mela','arancia','UVA'] to be like this: ['arancia','mela','Pera','UVA'] In the exercise it said to use the sorted() function with the cmp argument.
Doni
  • 75
  • 1
  • 1
  • 6
6
votes
3 answers

Bash, how to print out that files are the same when using cmp

cmp file1 file2 does nothing when the files are the same. So how do I print out that files are the same in shell script?
kulan
  • 1,353
  • 3
  • 15
  • 29
6
votes
5 answers

__cmp__ method is this not working as expected in Python 2.x?

class x: def __init__(self,name): self.name=name def __str__(self): return self.name def __cmp__(self,other): print("cmp method called with self="+str(self)+",other="+str(other)) return…
monojohnny
  • 5,894
  • 16
  • 59
  • 83
6
votes
2 answers

How are Javascript array compared?

Is there a standard defined how would JavaScript be compared, on Chrome console I get this [10,0,0] > [1,0,0] true [10,0,0] > [5,0,0] false [5, 0, 0, 0] < [10, 0, 0, 0] //repeatable false [10,0,0,0] > [9,0,0,0] false [11,0,0,0] >…
Anurag Uniyal
  • 85,954
  • 40
  • 175
  • 219
5
votes
4 answers

Understanding python object membership for sets

If I understand correctly, the __cmp__() function of an object is called in order to evaluate all objects in a collection while determining whether an object is a member, or 'in', the collection. However, this does not seem to be the case for…
jifa
  • 53
  • 4
5
votes
4 answers

How can i change the __cmp__ function of an instance (not in class)?

How can i change the __cmp__ function of an instance (not in class)? Ex: class foo: def __init__(self, num): self.num = num def cmp(self, other): return self.num - other.num # Change __cmp__ function in class works foo.__cmp__ =…
DaniloNC
  • 3,555
  • 2
  • 16
  • 8
1
2 3
9 10