0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Why did #python open up dictionary access to match objects? (`TypeError: '_sre.SRE_Match' object is not subscriptable`)

Last updated at Posted at 2019-04-14

3.4.8

 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 
 

3.7.2

 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' 
 

ref

re — Regular expression operations — Python 3.7.3 documentation

Easy access to group! It seems like. Thanks python

image

By the way ruby example

 [5] pry(main)> 'abc'.match(/b/)[0] 
 => "b" 
 

It may be easier to understand the dictionary

Original by Github issue

チャットメンバー募集

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

Twitter

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?