Zero sum in python 2.7

-3

Write a function in Python 2.7 that takes a list of integers as an argument. It should return True or False depending on whether there are any 2 integers in the argument list that sum to zero. [4,-4,9,6,5]

True

[6,5,-3,2]

False

Arlene

Posted 2018-05-28T17:48:55.743

Reputation: 13

Question was closed 2018-05-28T18:42:11.800

9

Welcome to PPCG! That's a nice challenge, but unfortunately, we don't like challenges that allow only one language. This challenge is also missing a winning criteria. I'd recommend you to look at few other of challenges there and use our sandbox next time.

– RedClover – 2018-05-28T17:56:06.663

I'm guessing this must be code golf as I can't see any other reasonable criteria. (I added the code golf tag, but if that is wrong feel free to specify the correct winning criteria and remove it.) – Jonathan Allan – 2018-05-28T18:09:43.360

6@Arlene what should we return for [0]? – ngn – 2018-05-28T18:24:02.853

Closely related – Mego – 2018-05-28T18:40:54.483

3

@JonathanAllan Please stop editing programming questions to make them on-topic. Either OP edit the winning criteria in themselves or we close (and optionally someone else repost) it.

– user202729 – 2018-05-29T04:05:26.720

1@user202729 I didn't think there was any harm, meta read and noted - it makes sense; thanks – Jonathan Allan – 2018-05-29T12:41:19.120

I think the challenge is too easy – mbomb007 – 2018-05-30T14:33:17.337

Answers

3

Python 2, 32 bytes

lambda a:any(-n in a for n in a)

Try it online!

Jonathan Allan

Posted 2018-05-28T17:48:55.743

Reputation: 67 804

0

R, 23 bytes

function(x)any(-x%in%x)

Try it online!

If full programs are allowed:

R, 21 bytes

any((x=scan())%in%-x)

Try it online!

JayCe

Posted 2018-05-28T17:48:55.743

Reputation: 2 655

2Yes any language is fine. Sorry I am new to this. Thank you! – Arlene – 2018-05-29T22:06:43.093

@Arlene Thank you and welcome to PPCG! – JayCe – 2018-05-30T00:01:14.243

@Arlene Please edit your question to reflect the fact that all languages are allowed. Also if you are interested in the shortest solution, I suggest you tag your question [tag:code-golf] – JayCe – 2018-05-30T00:04:22.833