This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Add match built-in function
Type: enhancement Stage: resolved
Components: Regular Expressions Versions: Python 3.8
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: MoKhaild, eric.snow, ezio.melotti, mrabarnett
Priority: normal Keywords:

Created on 2018-08-31 14:45 by MoKhaild, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (4)
msg324425 - (view) Author: mokhalid (MoKhaild) Date: 2018-08-31 14:45
match built-in function feature request:

what is the match function do?
the match function is doing something like if but with quick easy syntax that even beginners can use.

possible syntax:

match(list or string or dictionary):
  condition: event here
  condition: event here
#all conditions are applied at the same time as if not elif and else
#but you use elif or else.

ex:
match(list or string or dictionary):
  condition: event here
  condition: event here
    elif condition: event here
    else: event here
 

example of what I mean:
match([2,5,4,'Hello']):
  2: print('here is 2')
  6: print('here is 6')
    elif 'Hello': ('Hello world')
  8:print('here is 8')
    elif 'python': ('Hello world')
    else: print('MoKhalid')

the output should look like:
here is 2
Hello world
MoKhalid
msg324426 - (view) Author: mokhalid (MoKhaild) Date: 2018-08-31 14:57
sorry I forget to print text i mean:
match([2,5,4,'Hello']):
  2: print('here is 2')
  6: print('here is 6')
    elif 'Hello': print('Hello world')
  8:print('here is 8')
    elif 'python': print('Hello world')
    else: print('MoKhalid')
msg324428 - (view) Author: Eric Snow (eric.snow) * (Python committer) Date: 2018-08-31 15:15
Thanks for the proposal.  At first glance I actually kind of like the idea, though I can't offer much more feedback than that without taking some time to think it through. :)

That said, proposals like this for new syntax and other new language features are best suited for the python-ideas@python.org mailing list. [1]  I recommend you make a post there.  I'm closing the issue as "rejected" because it belongs on python-ideas instead of here, not because we're rejecting the idea. :)

Thanks again!  I hope you post something about this to python-ideas.

[1] https://mail.python.org/mailman/listinfo/python-ideas
msg324430 - (view) Author: mokhalid (MoKhaild) Date: 2018-08-31 15:17
Thanks so much, I will do it :)
History
Date User Action Args
2022-04-11 14:59:05adminsetgithub: 78735
2018-08-31 15:17:48MoKhaildsetmessages: + msg324430
2018-08-31 15:15:11eric.snowsetstatus: open -> closed

nosy: + eric.snow
messages: + msg324428

resolution: rejected
stage: resolved
2018-08-31 15:04:45MoKhaildsettitle: Add match built in functio -> Add match built-in function
2018-08-31 15:04:26MoKhaildsettitle: add match built in function -> Add match built in functio
2018-08-31 14:57:04MoKhaildsetmessages: + msg324426
2018-08-31 14:45:23MoKhaildcreate