[issue43900] string comprehension
New submission from David Alvarez Lombardi : As of now the best way to filter a str is to convert to list, filter, then join back to a str. I think a a string comprehension would be very useful for this. So to get only ascii_lower case chars given this string, s = "a1b2c3d4" I could do this filtered_s = c"ch for ch in s if ch in string.ascii_lowercase" instead of this. s_list = [] for i in range(len(s)): if s[i] in string.ascii_lowercase: s_list.append(s[i]) filtered_s = "".join(s_list) -- messages: 391480 nosy: alvarezdqal priority: normal severity: normal status: open title: string comprehension type: enhancement versions: Python 3.10 ___ Python tracker <https://bugs.python.org/issue43900> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue43899] separate builtin function
New submission from David Alvarez Lombardi : I frequently find myself doing the following for lists, sets, and dicts. passes = [x for x in seq if cond(x)] fails = [x for x in seq if not cond(x)] The proposed function would behave similarly to `filter`, but it would return a tuple of the passes iterable and fails iterable rather than just the passes. my_list = [-3, -2, -1, 0, 1, 2, 3] def is_positive(n): return n > 0 positives, negatives = separate(function=is_positive, iterable=my_list) -- messages: 391479 nosy: alvarezdqal priority: normal severity: normal status: open title: separate builtin function type: enhancement versions: Python 3.10 ___ Python tracker <https://bugs.python.org/issue43899> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com