You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
product_of_elems = functools.reduce(<spanclass="hljs-keyword">lambda</span> out, x: out * x, <collection>)
238
238
list_of_chars = list(<str>)
239
239
</code></pre>
240
-
<pre><codeclass="python language-python hljs"><bool> = <el> <spanclass="hljs-keyword">in</span> <collection> <spanclass="hljs-comment"># For dictionary it checks if key exists.</span>
241
-
index = <list>.index(<el>) <spanclass="hljs-comment"># Returns index of first occurrence or raises ValueError.</span>
240
+
<pre><codeclass="python language-python hljs">index = <list>.index(<el>) <spanclass="hljs-comment"># Returns index of first occurrence or raises ValueError.</span>
242
241
<list>.insert(index, <el>) <spanclass="hljs-comment"># Inserts item at index and moves the rest to the right.</span>
243
242
<el> = <list>.pop([index]) <spanclass="hljs-comment"># Removes and returns item at index or from the end.</span>
244
243
<list>.remove(<el>) <spanclass="hljs-comment"># Removes first occurrence of item or raises ValueError.</span>
<list> = <str>.splitlines(keepends=<spanclass="hljs-keyword">False</span>) <spanclass="hljs-comment"># Splits on line breaks. Keeps them if 'keepends'.</span>
412
411
<str> = <str>.join(<coll_of_strings>) <spanclass="hljs-comment"># Joins elements using string as separator.</span>
413
412
</code></pre>
414
-
<pre><codeclass="python language-python hljs"><str> = <str>.replace(old, new [, count])<spanclass="hljs-comment"># Replaces 'old' with 'new' at most 'count' times.</span>
413
+
<pre><codeclass="python language-python hljs"><bool> = <sub_str> <spanclass="hljs-keyword">in</span> <str><spanclass="hljs-comment"># Checks if string contains a substring.</span>
415
414
<bool> = <str>.startswith(<sub_str>) <spanclass="hljs-comment"># Pass tuple of strings for multiple options.</span>
416
415
<bool> = <str>.endswith(<sub_str>) <spanclass="hljs-comment"># Pass tuple of strings for multiple options.</span>
417
416
<int> = <str>.find(<sub_str>) <spanclass="hljs-comment"># Returns start index of first match or -1.</span>
418
417
<int> = <str>.index(<sub_str>) <spanclass="hljs-comment"># Same but raises ValueError.</span>
419
418
</code></pre>
420
-
<pre><codeclass="python language-python hljs"><bool> = <str>.isnumeric() <spanclass="hljs-comment"># True if str contains only numeric characters.</span>
419
+
<pre><codeclass="python language-python hljs"><str> = <str>.replace(old, new [, count]) <spanclass="hljs-comment"># Replaces 'old' with 'new' at most 'count' times.</span>
420
+
<bool> = <str>.isnumeric() <spanclass="hljs-comment"># True if str contains only numeric characters.</span>
421
421
<list> = textwrap.wrap(<str>, width) <spanclass="hljs-comment"># Nicely breaks string into lines.</span>
0 commit comments