🖥

Why did #python open up dictionary access to match objects? (`TypeErro

2019/04/15に公開

<h1> 3.4.8 </h1>

<pre> <code class="py">Python 3.4.8 (default, Apr 9 2018, 11:43:18)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-18)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import re
>>> re.search(r'b', 'abc').group(0)
'b'
>>> re.search(r'b', 'abc')[0]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: '_sre.SRE_Match' object is not subscriptable
</code> </pre>

<h1> 3.7.2 </h1>

<pre> <code class="py">Python 3.7.2 (default, Jan 13 2019, 12:50:01)
[Clang 10.0.0 (clang-1000.11.45.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import re
>>> re.search(r'b', 'abc').group(0)
'b'
>>> re.search(r'b', 'abc')[0]
'b'
</code> </pre>

<h1> ref </h1>

<p> <a href="https://docs.python.org/3/library/re.html">re — Regular expression operations — Python 3.7.3 documentation</a> </p>

<p> Easy access to group! It seems like. Thanks python </p>

<p><img src="https://user-images.githubusercontent.com/13635059/56090302-94def800-5edb-11e9-8602-8419364f73e1.png" alt="image"></p>

<h1> By the way ruby example </h1>

<pre> <code class="rb">[5] pry(main)> 'abc'.match(/b/)[0]
=> "b"
</code> </pre>

<p> It may be easier to understand the dictionary </p>

Original by Github issue

https://github.com/YumaInaura/YumaInaura/issues/1281

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

https://line.me/ti/g2/eEPltQ6Tzh3pYAZV8JXKZqc7PJ6L0rpm573dcQ

Twitter

https://twitter.com/YumaInaura

公開日時

2019-04-15

Discussion