LoginSignup
0
0

More than 3 years have passed since last update.

「【Ruby】配列から重複していない要素を取得する」を参考にSymPyLiveでやってみた。

Last updated at Posted at 2021-01-07

(オリジナルポスト)
https://qiita.com/suzu12/items/af0ccbca88f33dec2fda#実践
https://qiita.com/suzu12/items/af0ccbca88f33dec2fda

SymPy Liveで

Pythonでリストから重複した要素を抽出して、Pythonでlistのlistを引き算をしています。
もっと短くなるような気がします。教えて下さい。

sum( [i for i in [1,2,3] if i not in [x for x in set([1,2,3]) if [1,2,3].count(x) > 1]])
6
sum( [i for i in [3,2,3] if i not in [x for x in set([3,2,3]) if [3,2,3].count(x) > 1]])
2
sum( [i for i in [3,3,3] if i not in [x for x in set([3,3,3]) if [3,3,3].count(x) > 1]])
0

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