LoginSignup
1
1

More than 5 years have passed since last update.

プログラマの考えが・・身につく本より(Python):配列のおさらい

Last updated at Posted at 2016-04-26

配列のおさらいという項目で
Pythonのリストを勉強中

配列の取得と検索より

特定の値を検索する。
C++での解答コード

const int ARRAY_SIZE = 10;
int intArray[ARRAY_SIZE] = {4,5,9,12,-4,0,-57,30987,-287,1};
int targetValue = 12;
int targetPos = 0;
while((intArray[targetPos] != targetValue) && (targetPos < ARRAY_SIZE))
    targetPos++;

自分のPythonコード

#!/usr/bin/env python
#coding:utf-8

def Search(targetValue):
    ARRAY_SIZE = [4,5,9,12,-4,0,-57,30987,-287,1]
    for x in ARRAY_SIZE:
       if targetValue == x:
           return x
       else:
           continue

    if targetValue != x:
        print("not found")

・・・・(ターミナル実行)
>>> from test33 import Search
>>> Search(12)
12
>>> 

とにかくif文で考えているけどこれでいいのかな。
続けてみます。

1
1
4

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
1