LoginSignup
0
0

More than 3 years have passed since last update.

Pythonを脱出する自分なりのステップ

Last updated at Posted at 2020-08-03

その1

jupyternote を何とかする

カーネルを作れば拡張出来るらしい
https://dandy-tech.hatenablog.jp/entry/2019/06/20/000119

やはりPythonがPythonである理由は、
アプリケーション自体の作りだす、価値なんだと思う。

その2

pandasを何とかする

これは絶妙なところ。pandasなきpythonなど、使う意味さえなくなりそうである。
Excel → pandasが唯一の入り口に思えてくる。

その3

AIを何とかする

これは時間の問題のような気がする。
要するに計算の外の話なので、IN-OUTができたらShellでもいいかも

Python

ここからは前の話・・・

元ネタ
https://towardsdatascience.com/10-algorithms-to-solve-before-your-python-coding-interview-feb74fb9bc27

文字列の操作

1. 逆整数

整数が与えられた場合, 桁を逆にした整数を返します.
注意: 整数は正負のどちらでも構いません.

def solution(x):
    string = str(x)
    if string[0] == '-':
        return int('-'+string[:0:-1])
    else:
        return int(string[::-1])    
print(solution(-231))
print(solution(345))

Output:
-132
543

まずはスライスの練習。
負の整数を入れることがポイント

2. 平均語数の長さ

与えられた文について、平均的な単語の長さを返します。
注意: 最初に句読点を削除することを忘れないでください.


sentence1 = "Hi all, my name is Tom...I am originally from Australia."
sentence2 = "I need to work very hard to learn more about algorithms in Python!"

def solution(sentence):
    for p in "!?',;.":
        sentence = sentence.replace(p, '')
    words = sentence.split()
    return round(sum(len(word) for word in words)/len(words),2)

print(solution(sentence1))
print(solution(sentence2))

Output:
4.2
4.08

一般的な文字列を使った計算アルゴリズムでは
.replace(),.split()といったメソッドがポイントになる。

つづく

0
0
0

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
0
0