From f7d350181772d6023b4c5c3f8d953076b43e52ee Mon Sep 17 00:00:00 2001 From: 30secondsofcode <30secondsofcode@gmail.com> Date: Wed, 9 Oct 2019 10:16:18 +0000 Subject: [PATCH] Travis build: 151 --- README.md | 9 +++++---- snippet_data/snippetList.json | 4 ++-- snippet_data/snippets.json | 8 ++++---- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index f45b1d323..86642cfb6 100644 --- a/README.md +++ b/README.md @@ -1965,19 +1965,20 @@ split_lines('This\nis a\nmultiline\nstring.\n') # 'This\nis a\nmultiline\nstring Casts the provided value as an array if it's not one. -Use `isinstance()` to check if the given value is a list and return it as-is or encapsulated in a list accordingly. +Use `isinstance()` to check if the given value is enumerable and return it by using `list()` or encapsulated in a list accordingly. ```py def cast_list(val): - return val if isinstance(val, list) else [val] + return list(val) if isinstance(val, (tuple, list, set, dict)) else [val] ```
Examples ```py -cast_list('foo'); # ['foo'] -cast_list([1]); # [1] +cast_list('foo') # ['foo'] +cast_list([1]) # [1] +cast_list(('foo', 'bar')) # ['foo', 'bar'] ```
diff --git a/snippet_data/snippetList.json b/snippet_data/snippetList.json index cf3716450..bdb5903a4 100644 --- a/snippet_data/snippetList.json +++ b/snippet_data/snippetList.json @@ -160,7 +160,7 @@ "type": "snippetListing", "title": "cast_list", "attributes": { - "text": "Casts the provided value as an array if it's not one.\n\nUse `isinstance()` to check if the given value is a list and return it as-is or encapsulated in a list accordingly.\n\n", + "text": "Casts the provided value as an array if it's not one.\n\nUse `isinstance()` to check if the given value is enumerable and return it by using `list()` or encapsulated in a list accordingly.\n\n", "tags": [ "utility", "list", @@ -168,7 +168,7 @@ ] }, "meta": { - "hash": "4a9cb79c384099543163d3b1b7e2fa389a4cc373b2b76b17563a4597ed29a4c7" + "hash": "776892dc64825137f40f9fe45a1113b94761f7a7f187ce11ea1fa9d4de3787ee" } }, { diff --git a/snippet_data/snippets.json b/snippet_data/snippets.json index 67679e191..3bc63ccb5 100644 --- a/snippet_data/snippets.json +++ b/snippet_data/snippets.json @@ -211,10 +211,10 @@ "type": "snippet", "attributes": { "fileName": "cast_list.md", - "text": "Casts the provided value as an array if it's not one.\n\nUse `isinstance()` to check if the given value is a list and return it as-is or encapsulated in a list accordingly.\n\n", + "text": "Casts the provided value as an array if it's not one.\n\nUse `isinstance()` to check if the given value is enumerable and return it by using `list()` or encapsulated in a list accordingly.\n\n", "codeBlocks": { - "code": "def cast_list(val):\n return val if isinstance(val, list) else [val]", - "example": "cast_list('foo'); # ['foo']\ncast_list([1]); # [1]" + "code": "def cast_list(val):\n return list(val) if isinstance(val, (tuple, list, set, dict)) else [val]", + "example": "cast_list('foo') # ['foo']\ncast_list([1]) # [1]\ncast_list(('foo', 'bar')) # ['foo', 'bar']" }, "tags": [ "utility", @@ -223,7 +223,7 @@ ] }, "meta": { - "hash": "4a9cb79c384099543163d3b1b7e2fa389a4cc373b2b76b17563a4597ed29a4c7" + "hash": "776892dc64825137f40f9fe45a1113b94761f7a7f187ce11ea1fa9d4de3787ee" } }, {