-3
\$\begingroup\$

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

\$\endgroup\$
7
  • 9
    \$\begingroup\$ 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. \$\endgroup\$
    – RedClover
    May 28, 2018 at 17:56
  • \$\begingroup\$ 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.) \$\endgroup\$ May 28, 2018 at 18:09
  • 6
    \$\begingroup\$ @Arlene what should we return for [0]? \$\endgroup\$
    – ngn
    May 28, 2018 at 18:24
  • 3
    \$\begingroup\$ @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. \$\endgroup\$
    – DELETE_ME
    May 29, 2018 at 4:05
  • 1
    \$\begingroup\$ @user202729 I didn't think there was any harm, meta read and noted - it makes sense; thanks \$\endgroup\$ May 29, 2018 at 12:41

2 Answers 2

3
\$\begingroup\$

Python 2, 32 bytes

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

Try it online!

\$\endgroup\$
0
\$\begingroup\$

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!

\$\endgroup\$
3
  • 2
    \$\begingroup\$ Yes any language is fine. Sorry I am new to this. Thank you! \$\endgroup\$
    – Arlene
    May 29, 2018 at 22:06
  • \$\begingroup\$ @Arlene Thank you and welcome to PPCG! \$\endgroup\$
    – JayCe
    May 30, 2018 at 0:01
  • \$\begingroup\$ @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 code-golf \$\endgroup\$
    – JayCe
    May 30, 2018 at 0:04

Not the answer you're looking for? Browse other questions tagged or ask your own question.