LoginSignup
1
0

More than 5 years have passed since last update.

Python > list | tuple > [数値の組合せlist]の中に[tuple定義の同じ数値組合せ]があるか確認する

Last updated at Posted at 2018-04-28
動作環境
GeForce GTX 1070 (8GB)
ASRock Z170M Pro4S [Intel Z170chipset]
Ubuntu 16.04.4 LTS desktop amd64
TensorFlow v1.7.0
cuDNN v5.1 for Linux
CUDA v8.0
Python 3.5.2
IPython 6.0.0 -- An enhanced Interactive Python.
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
GNU bash, version 4.3.48(1)-release (x86_64-pc-linux-gnu)
scipy v0.19.1
geopandas v0.3.0
MATLAB R2017b (Home Edition)
ADDA v.1.3b6
gnustep-gui-runtime v0.24.0-3.1
PyMieScatt v1.7.0
(2, 9) [[2, 5], [3, 5], [3, 6], [4, 6], [4, 7], [0, 7], [0, 8], [1, 8], [1, 9], [2, 9]]

右側のlistの中に左側のtuple(2, 9)があるか確認したい。

alist = [[0, 2], [0, 3]]
atpl = (0,2)

if atpl in alist:
    print('in1')

if atpl in tuple(alist):
    print('in2')

if list(atpl) in alist:
    print('in3')

run
in3

同じ土俵に上げることで比較できるようになる。

上記の例ではlistにすることで希望の処理になった。

教えていただいた事項

(追記 2018/04/28)

@shiracamus さんのコメントにてtupleへの変換方法を教えていただきました。

情報感謝です。

1
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0