推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
Bill1
V2EX  ›  Python

Python 列出两个列表中一个不含另一个的值

  •  
  •   Bill1 · Jan 21, 2017 · 4585 views
    This topic created in 3573 days ago, the information mentioned may be changed or developed.

    Google foo.bar游戏,本地测试正常,在游戏上提交了几次都测试失败了,代码如下,请大家帮我看看。

    def answer(x, y):
    	# your code here
    	a=0
    	while True:
    		if a==len(x):
    			a=0
    			while True:
    				if y[a] in x:
    					a=a+1
    				else:
    					print(y[a])
    					return
    		elif x[a] in y:
    			a=a+1
    		else:
    			print(x[a])
    			return
    

    #只有一个两个列表中一个不含另一个的值,输出的是一个值

    ryd994
    ryd994
    Jan 21, 2017 via Android
    1
    这种东西在线问被查到会很惨的
    ryd994
    ryd994
    Jan 21, 2017 via Android
    2
    @livid 隐藏本帖比较好
    一方面这种彩蛋招聘还要作弊就没意思了
    其实被 Google 索引到的话对楼主不利
    Victor215
    Victor215
    Jan 21, 2017
    3
    可以用 set
    AlisaDestiny
    AlisaDestiny
    Jan 21, 2017
    4
    ```python
    def answer(x,y):
    a = [e for e in x if e not in y]
    b = [e for e in y if e not in x]
    print(a+b)

    ```
    Bill1
    Bill1
    OP
    Jan 21, 2017
    5
    @ryd994 我没打算用这种方式进 Google ,我只是纳闷本地测试没问题而提交就不行了

    @AlisaDestiny 仍然本地测试没问题而提交就不行了

    纳闷。。。。
    jmc891205
    jmc891205
    Jan 21, 2017
    6
    一般就是一些边界条件没搞对 有些 testcase 过不了 你自己再查查吧
    herozhang
    herozhang
    Jan 21, 2017
    7
    可能的点:
    1. 缺少对输入值的检查,例如传入的参数是乱七八糟的其他东西
    2. 性能(速度、内存等)不达标
    cyrbuzz
    cyrbuzz
    PRO
    Jan 22, 2017
    8
    或许是 return 问题,这样写 return 是 None 。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2858 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 13:06 · PVG 21:06 · LAX 05:06 · JFK 08:06
    ♥ Do have faith in what you're doing.