chunk_id stringlengths 36 36 | source stringclasses 35
values | source_url stringlengths 0 290 | upstream_license stringclasses 1
value | document_id stringlengths 36 36 | chunk_index int64 0 324k | retrieved_at stringclasses 2
values | chunker_version stringclasses 4
values | content_hash stringlengths 15 64 | content stringlengths 50 44.7k | namespace stringclasses 9
values | source_name stringclasses 35
values | raw_text stringlengths 50 44.7k | cleaned_text stringlengths 50 44.7k | tags stringclasses 49
values | collection_name stringclasses 11
values |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
70f0ada3-19b1-4ae8-8269-7264e8f1d027 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/undirected-tree-dfs-bfs.md | unknown | 351fd270-741b-419a-8fb4-ec7c3f39e852 | 3 | SemanticChunker@1.0.0 | 844dc56dcf7b9e6fbbf4cd3082020c6c99eff390554e89b29d791776c5a44803 | [Depth-First Search (DFS) > Conclusion]
## Conclusion
Both DFS and BFS are powerful algorithms for traversing trees and graphs. The choice between them depends on the specific requirements of your application. DFS is often more memory-efficient for deep trees, while BFS is better for finding the shortest path in unwe... | unknown | unknown | [Depth-First Search (DFS) > Conclusion]
## Conclusion
Both DFS and BFS are powerful algorithms for traversing trees and graphs. The choice between them depends on the specific requirements of your application. DFS is often more memory-efficient for deep trees, while BFS is better for finding the shortest path in unwe... | [Depth-First Search (DFS) > Conclusion]
## Conclusion
Both DFS and BFS are powerful algorithms for traversing trees and graphs. The choice between them depends on the specific requirements of your application. DFS is often more memory-efficient for deep trees, while BFS is better for finding the shortest path in unwe... | code_snippets | ||
72a33db2-a8ad-48ae-92ef-a2476c1fce2d | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/undirected-tree-dfs-bfs.md | unknown | 351fd270-741b-419a-8fb4-ec7c3f39e852 | 2 | SemanticChunker@1.0.0 | 92783b619ae3f03620a680b7f93337d4f2fc72215dea3b1a0b5244712525d038 | [Depth-First Search (DFS) > Breadth-First Search (BFS)]
## Breadth-First Search (BFS)
Breadth-First Search (BFS) is a traversal algorithm that explores **all the neighbors of a node before moving on to the next level**. It can be implemented using a queue.
@[Quick refresher](/js/s/data-structures-queue)
```js
const... | unknown | unknown | [Depth-First Search (DFS) > Breadth-First Search (BFS)]
## Breadth-First Search (BFS)
Breadth-First Search (BFS) is a traversal algorithm that explores **all the neighbors of a node before moving on to the next level**. It can be implemented using a queue.
@[Quick refresher](/js/s/data-structures-queue)
```js
const... | [Depth-First Search (DFS) > Breadth-First Search (BFS)]
## Breadth-First Search (BFS)
Breadth-First Search (BFS) is a traversal algorithm that explores **all the neighbors of a node before moving on to the next level**. It can be implemented using a queue.
@[Quick refresher](/js/s/data-structures-queue)
```js
const... | code_snippets | ||
7deabdf9-2f06-4bc8-a0b0-6f8d22e40ad1 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/undirected-tree-dfs-bfs.md | unknown | 351fd270-741b-419a-8fb4-ec7c3f39e852 | 1 | SemanticChunker@1.0.0 | a29b7d91f5c51f51e036cc26bb606e1ee55da641838477b0aff665a0dd7e8836 | [Depth-First Search (DFS)]
## Depth-First Search (DFS)
Depth-First Search (DFS) is a traversal algorithm that explores **as far as possible along each branch before backtracking**. DFS can be implemented **recursively or iteratively**, using an explicit stack. I find the iterative approach to be more efficient and ea... | unknown | unknown | [Depth-First Search (DFS)]
## Depth-First Search (DFS)
Depth-First Search (DFS) is a traversal algorithm that explores **as far as possible along each branch before backtracking**. DFS can be implemented **recursively or iteratively**, using an explicit stack. I find the iterative approach to be more efficient and ea... | [Depth-First Search (DFS)]
## Depth-First Search (DFS)
Depth-First Search (DFS) is a traversal algorithm that explores **as far as possible along each branch before backtracking**. DFS can be implemented **recursively or iteratively**, using an explicit stack. I find the iterative approach to be more efficient and ea... | code_snippets | ||
cbf19f48-f5bc-45d5-8b0a-f8a74080196d | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/undirected-tree-dfs-bfs.md | unknown | 351fd270-741b-419a-8fb4-ec7c3f39e852 | 0 | SemanticChunker@1.0.0 | 64e8250dbe60bf8acb25afde41d5bce65676941c37fe5606f4d142250499b069 | ---
title: How can I traverse an undirected tree using DFS or BFS in JavaScript?
shortTitle: DFS/BFS tree traversal
language: javascript
tags: [algorithm,array]
cover: japanese-cityscape
excerpt: Learn how to traverse an undirected tree using Depth-First Search (DFS) or Breadth-First Search (BFS) in JavaScript.
listed:... | unknown | unknown | ---
title: How can I traverse an undirected tree using DFS or BFS in JavaScript?
shortTitle: DFS/BFS tree traversal
language: javascript
tags: [algorithm,array]
cover: japanese-cityscape
excerpt: Learn how to traverse an undirected tree using Depth-First Search (DFS) or Breadth-First Search (BFS) in JavaScript.
listed:... | ---
title: How can I traverse an undirected tree using DFS or BFS in JavaScript?
shortTitle: DFS/BFS tree traversal
language: javascript
tags: [algorithm,array]
cover: japanese-cityscape
excerpt: Learn how to traverse an undirected tree using Depth-First Search (DFS) or Breadth-First Search (BFS) in JavaScript.
listed:... | code_snippets | ||
892ce9bd-6009-415e-a55d-585e8710b3d6 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/walk-through-object.md | unknown | b1af2395-247a-41bc-b78c-de3fff02ac78 | 0 | SemanticChunker@1.0.0 | 71563836876d0b2de178393c8b050c1c02b3b715c8e3361f89144f505ec544c4 | ---
title: Walk through a JavaScript object depth-first
shortTitle: Depth-first walk through object
language: javascript
tags: [object,recursion,generator]
cover: bridge
excerpt: Create a generator that walks through all the keys of a given object.
listed: true
dateModified: 2024-06-05
---
Given an **object with deepl... | unknown | unknown | ---
title: Walk through a JavaScript object depth-first
shortTitle: Depth-first walk through object
language: javascript
tags: [object,recursion,generator]
cover: bridge
excerpt: Create a generator that walks through all the keys of a given object.
listed: true
dateModified: 2024-06-05
---
Given an **object with deepl... | ---
title: Walk through a JavaScript object depth-first
shortTitle: Depth-first walk through object
language: javascript
tags: [object,recursion,generator]
cover: bridge
excerpt: Create a generator that walks through all the keys of a given object.
listed: true
dateModified: 2024-06-05
---
Given an **object with deepl... | code_snippets | ||
1b607f64-c65c-4fd8-b53f-8b9497a5989e | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/void-links.md | unknown | f3032b27-4fe4-40b0-8631-ae80cf2ed8bd | 0 | SemanticChunker@1.0.0 | 059a9429176c9beb58e56ba67783f9711c51369d10154a7997901818b0ade3c9 | ---
title: Avoid "javascript:void(0)" for empty links
language: javascript
tags: [browser,accessibility]
cover: white-flower
excerpt: There are many ways to create empty links, some more appropriate than others. Learn how to best handle empty links with this quick tip.
listed: true
dateModified: 2021-06-12
---
There a... | unknown | unknown | ---
title: Avoid "javascript:void(0)" for empty links
language: javascript
tags: [browser,accessibility]
cover: white-flower
excerpt: There are many ways to create empty links, some more appropriate than others. Learn how to best handle empty links with this quick tip.
listed: true
dateModified: 2021-06-12
---
There a... | ---
title: Avoid "javascript:void(0)" for empty links
language: javascript
tags: [browser,accessibility]
cover: white-flower
excerpt: There are many ways to create empty links, some more appropriate than others. Learn how to best handle empty links with this quick tip.
listed: true
dateModified: 2021-06-12
---
There a... | code_snippets | ||
5fa800a2-e083-4d70-9267-62e6648e7f07 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/vector-angle.md | unknown | 38d600ed-e4a4-4270-ae63-a323661fef62 | 0 | SemanticChunker@1.0.0 | 19723678c4a08a92bdea8476c8a620d482bb30cd789cb746b60287c52c8aa21a | ---
title: Calculate the angle between two vectors in JavaScript
shortTitle: Vector angle
language: javascript
tags: [math]
cover: purple-pier
excerpt: Learn how to calculate the angle (theta) between two vectors in JavaScript.
listed: true
dateModified: 2024-05-16
---
Given two vectors, you can calculate the angle be... | unknown | unknown | ---
title: Calculate the angle between two vectors in JavaScript
shortTitle: Vector angle
language: javascript
tags: [math]
cover: purple-pier
excerpt: Learn how to calculate the angle (theta) between two vectors in JavaScript.
listed: true
dateModified: 2024-05-16
---
Given two vectors, you can calculate the angle be... | ---
title: Calculate the angle between two vectors in JavaScript
shortTitle: Vector angle
language: javascript
tags: [math]
cover: purple-pier
excerpt: Learn how to calculate the angle (theta) between two vectors in JavaScript.
listed: true
dateModified: 2024-05-16
---
Given two vectors, you can calculate the angle be... | code_snippets | ||
24e03130-4e9e-49c7-a16b-a5568c699f00 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/variable-hoisting.md | unknown | 16c72ee5-01a6-4df1-ba5d-133b6f2103fb | 4 | SemanticChunker@1.0.0 | 72cda535236206152c956a4e7fae0af4cd9ee6894649e17d73c38234368e77da | [function > Best practices]
## Best practices
- Always define variables, functions, objects and classes before using them. ESLint can probably help you with that.
- If your environment/team allows it, prefer `const` and `let`over `var` to minimize headaches.
- If possible, use only arrow functions or `function` decla... | unknown | unknown | [function > Best practices]
## Best practices
- Always define variables, functions, objects and classes before using them. ESLint can probably help you with that.
- If your environment/team allows it, prefer `const` and `let`over `var` to minimize headaches.
- If possible, use only arrow functions or `function` decla... | [function > Best practices]
## Best practices
- Always define variables, functions, objects and classes before using them. ESLint can probably help you with that.
- If your environment/team allows it, prefer `const` and `let`over `var` to minimize headaches.
- If possible, use only arrow functions or `function` decla... | code_snippets | ||
2f477255-e8aa-4664-879e-010159f02371 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/variable-hoisting.md | unknown | 16c72ee5-01a6-4df1-ba5d-133b6f2103fb | 0 | SemanticChunker@1.0.0 | 0f859e42f0063ef645dbc34dd39d5e0bbe99f61c743cbf08dd7050e76d9b2781 | ---
title: What is hoisting in JavaScript?
shortTitle: Hoisting introduction
language: javascript
tags: [type,variable]
cover: boat-port
excerpt: Hoisting comes up a lot during JavaScript interviews. It's a concept that may require some getting used to, so read our guide to learn more.
listed: true
dateModified: 2023-0... | unknown | unknown | ---
title: What is hoisting in JavaScript?
shortTitle: Hoisting introduction
language: javascript
tags: [type,variable]
cover: boat-port
excerpt: Hoisting comes up a lot during JavaScript interviews. It's a concept that may require some getting used to, so read our guide to learn more.
listed: true
dateModified: 2023-0... | ---
title: What is hoisting in JavaScript?
shortTitle: Hoisting introduction
language: javascript
tags: [type,variable]
cover: boat-port
excerpt: Hoisting comes up a lot during JavaScript interviews. It's a concept that may require some getting used to, so read our guide to learn more.
listed: true
dateModified: 2023-0... | code_snippets | ||
30287c7e-9a5d-414e-958a-ce40c554324a | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/variable-hoisting.md | unknown | 16c72ee5-01a6-4df1-ba5d-133b6f2103fb | 2 | SemanticChunker@1.0.0 | be6fd5a8c314c8ae7a22dda037a17f80523aa9b1baeb21a271e1f832cbcb0a93 | [function > var]
## var
`var` declarations on the other hand behave differently, returning `undefined` when accessed before initialization. For example:
```js
console.log(x); // logs 'undefined'
f(); // throws 'Uncaught TypeError: f is not a function'
var x = 1;
var f = () => 'Hi!';
console.log(x); // logs '1'
f()... | unknown | unknown | [function > var]
## var
`var` declarations on the other hand behave differently, returning `undefined` when accessed before initialization. For example:
```js
console.log(x); // logs 'undefined'
f(); // throws 'Uncaught TypeError: f is not a function'
var x = 1;
var f = () => 'Hi!';
console.log(x); // logs '1'
f()... | [function > var]
## var
`var` declarations on the other hand behave differently, returning `undefined` when accessed before initialization. For example:
```js
console.log(x); // logs 'undefined'
f(); // throws 'Uncaught TypeError: f is not a function'
var x = 1;
var f = () => 'Hi!';
console.log(x); // logs '1'
f()... | code_snippets | ||
9c55f540-4ad6-4188-b1d1-5129d5950fc4 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/variable-hoisting.md | unknown | 16c72ee5-01a6-4df1-ba5d-133b6f2103fb | 1 | SemanticChunker@1.0.0 | b6c7ce3d10dfd14826053b3eca34ed78a46eee0f6e4095759117b1640c34cf42 | [function]
## function
When using `function` declarations, the function can be called before it's defined and it will work as expected. For example:
```js
hello(); // logs 'Hello world!'
function hello() {
console.log('Hello world!');
}
hello(); // logs 'Hello world!'
```
In the example above the `function` decl... | unknown | unknown | [function]
## function
When using `function` declarations, the function can be called before it's defined and it will work as expected. For example:
```js
hello(); // logs 'Hello world!'
function hello() {
console.log('Hello world!');
}
hello(); // logs 'Hello world!'
```
In the example above the `function` decl... | [function]
## function
When using `function` declarations, the function can be called before it's defined and it will work as expected. For example:
```js
hello(); // logs 'Hello world!'
function hello() {
console.log('Hello world!');
}
hello(); // logs 'Hello world!'
```
In the example above the `function` decl... | code_snippets | ||
fb06841b-47d9-483d-b56a-874022a554fe | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/variable-hoisting.md | unknown | 16c72ee5-01a6-4df1-ba5d-133b6f2103fb | 3 | SemanticChunker@1.0.0 | 2f20f7f251ced58fc695665df61b5a95c046f7718ff543b74a03b5586992f74f | [function > const and let]
## const and let
Finally, `const` and `let` declarations are hoisted, but they are not initialized to `undefined`. Instead, they will give you an error, which is also how `class` declarations behave. For example:
```js
console.log(y); // throws 'Uncaught ReferenceError: Cannot access "y" b... | unknown | unknown | [function > const and let]
## const and let
Finally, `const` and `let` declarations are hoisted, but they are not initialized to `undefined`. Instead, they will give you an error, which is also how `class` declarations behave. For example:
```js
console.log(y); // throws 'Uncaught ReferenceError: Cannot access "y" b... | [function > const and let]
## const and let
Finally, `const` and `let` declarations are hoisted, but they are not initialized to `undefined`. Instead, they will give you an error, which is also how `class` declarations behave. For example:
```js
console.log(y); // throws 'Uncaught ReferenceError: Cannot access "y" b... | code_snippets | ||
1c0f352a-9c75-49bd-b06e-7fcc87591575 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/variable-scope.md | unknown | 7da33765-6ef0-4b31-b2f6-98677006a6c7 | 1 | SemanticChunker@1.0.0 | 4b2dbce728b7594493721a23ff9623ddaf7709748c7b9d61019119656d5b7841 | [Variable definition]
## Variable definition
JavaScript provides two ways to define a variable (`var` and `let`) and one way to define a constant value (`const`).
`let` and `const` behave the same in terms of scope, both being block scoped (see below). On the other hand, `var` behaves differently by being function s... | unknown | unknown | [Variable definition]
## Variable definition
JavaScript provides two ways to define a variable (`var` and `let`) and one way to define a constant value (`const`).
`let` and `const` behave the same in terms of scope, both being block scoped (see below). On the other hand, `var` behaves differently by being function s... | [Variable definition]
## Variable definition
JavaScript provides two ways to define a variable (`var` and `let`) and one way to define a constant value (`const`).
`let` and `const` behave the same in terms of scope, both being block scoped (see below). On the other hand, `var` behaves differently by being function s... | code_snippets | ||
23b1a5cd-9932-499b-8346-b46f4e6f4353 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/variable-scope.md | unknown | 7da33765-6ef0-4b31-b2f6-98677006a6c7 | 2 | SemanticChunker@1.0.0 | 200cc4dcc686139d6b8a272bb3728ab69e3ac0021543c5d9fba9dca7e5d8b260 | [Variable definition > Scope]
## Scope
When we talk about scope, we mean the visibility of one or more entities (e.g variables) to certain parts of our code. There are two types of scopes: global and local. Local scope can in turn be separated into block, function and other types of more specific scopes.
**Global sc... | unknown | unknown | [Variable definition > Scope]
## Scope
When we talk about scope, we mean the visibility of one or more entities (e.g variables) to certain parts of our code. There are two types of scopes: global and local. Local scope can in turn be separated into block, function and other types of more specific scopes.
**Global sc... | [Variable definition > Scope]
## Scope
When we talk about scope, we mean the visibility of one or more entities (e.g variables) to certain parts of our code. There are two types of scopes: global and local. Local scope can in turn be separated into block, function and other types of more specific scopes.
**Global sc... | code_snippets | ||
653c8a5e-a22d-45db-9c51-8361c4d2b0f5 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/variable-scope.md | unknown | 7da33765-6ef0-4b31-b2f6-98677006a6c7 | 0 | SemanticChunker@1.0.0 | 57bed305277e24f918271785fc77e46261c579f0db0c81b062016d9582d9f8a8 | ---
title: Understanding JavaScript variables and scopes
shortTitle: Variables and scopes
language: javascript
tags: [type,variable]
cover: periscope
excerpt: JavaScript developers often get confused by JavaScript's variables and scope. Here's a quick guide to understanding these concepts.
listed: true
dateModified: 20... | unknown | unknown | ---
title: Understanding JavaScript variables and scopes
shortTitle: Variables and scopes
language: javascript
tags: [type,variable]
cover: periscope
excerpt: JavaScript developers often get confused by JavaScript's variables and scope. Here's a quick guide to understanding these concepts.
listed: true
dateModified: 20... | ---
title: Understanding JavaScript variables and scopes
shortTitle: Variables and scopes
language: javascript
tags: [type,variable]
cover: periscope
excerpt: JavaScript developers often get confused by JavaScript's variables and scope. Here's a quick guide to understanding these concepts.
listed: true
dateModified: 20... | code_snippets | ||
6a352679-f4de-40cc-9a34-9ea715bc9d57 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/value-not-equal-to-itself.md | unknown | df8dff39-935e-4b99-b66e-dfe4579d7c69 | 0 | SemanticChunker@1.0.0 | 8d23e96a8545f5ebc65562cdd4c9cbbfba3d4502c068c4ad2920f20fa0560019 | ---
title: What is the only value not equal to itself in JavaScript?
shortTitle: The only value not equal to itself
language: javascript
tags: [type,comparison]
cover: eagle
excerpt: Did you know there's a JavaScript value that's not equal to itself?
listed: true
dateModified: 2021-12-12
---
`NaN` (Not-a-Number) is th... | unknown | unknown | ---
title: What is the only value not equal to itself in JavaScript?
shortTitle: The only value not equal to itself
language: javascript
tags: [type,comparison]
cover: eagle
excerpt: Did you know there's a JavaScript value that's not equal to itself?
listed: true
dateModified: 2021-12-12
---
`NaN` (Not-a-Number) is th... | ---
title: What is the only value not equal to itself in JavaScript?
shortTitle: The only value not equal to itself
language: javascript
tags: [type,comparison]
cover: eagle
excerpt: Did you know there's a JavaScript value that's not equal to itself?
listed: true
dateModified: 2021-12-12
---
`NaN` (Not-a-Number) is th... | code_snippets | ||
88302f3f-dc07-466d-a5db-e5c7132b887c | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/value-as-number.md | unknown | d2ca369d-6b42-4b78-b9e6-c1ed3da1b246 | 0 | SemanticChunker@1.0.0 | 74a92f159625a5d5a8b016a92a7be622e2e5dff7092f0d77fb119402639a9f14 | ---
title: You can get the value of an input element as a number
shortTitle: Input element value as number
language: javascript
tags: [browser,input]
cover: mac-and-coffee
excerpt: Ever wanted to get the value of an HTML input element as a number? Learn an easy way to do it with this handy trick.
listed: true
dateModif... | unknown | unknown | ---
title: You can get the value of an input element as a number
shortTitle: Input element value as number
language: javascript
tags: [browser,input]
cover: mac-and-coffee
excerpt: Ever wanted to get the value of an HTML input element as a number? Learn an easy way to do it with this handy trick.
listed: true
dateModif... | ---
title: You can get the value of an input element as a number
shortTitle: Input element value as number
language: javascript
tags: [browser,input]
cover: mac-and-coffee
excerpt: Ever wanted to get the value of an HTML input element as a number? Learn an easy way to do it with this handy trick.
listed: true
dateModif... | code_snippets | ||
079ee32a-6039-495f-9793-195cb04e5f9f | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/validate-object-properties.md | unknown | 553c0e54-5258-4207-becb-dd92f24b0eb9 | 1 | SemanticChunker@1.0.0 | c21e7af8925206741cd5e35db712d2c1872fb1db7c7381b6f490a2c5e8f5da98 | [Validate against an array of keys]
## Validate against an array of keys
Given an **array of keys**, you can use `Object.keys()` to compare the keys of an object to the specified array. This will ensure that the object contains only the keys specified in the array.
Depending on your needs, you can **loosely check** ... | unknown | unknown | [Validate against an array of keys]
## Validate against an array of keys
Given an **array of keys**, you can use `Object.keys()` to compare the keys of an object to the specified array. This will ensure that the object contains only the keys specified in the array.
Depending on your needs, you can **loosely check** ... | [Validate against an array of keys]
## Validate against an array of keys
Given an **array of keys**, you can use `Object.keys()` to compare the keys of an object to the specified array. This will ensure that the object contains only the keys specified in the array.
Depending on your needs, you can **loosely check** ... | code_snippets | ||
2f3b49eb-19c3-4cfd-93e6-07151e02ae03 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/validate-object-properties.md | unknown | 553c0e54-5258-4207-becb-dd92f24b0eb9 | 2 | SemanticChunker@1.0.0 | f8889d41762f18d2cb5932843c45e22fe8851e2ae7b4107feab601acd9a49350 | [Validate against an array of keys > Validate against another object]
## Validate against another object
If you want to validate an object against **another object**, you simply need to **retrieve the keys** of the second object, using `Object.keys()`, and compare them to the keys of the first object. The rest of the... | unknown | unknown | [Validate against an array of keys > Validate against another object]
## Validate against another object
If you want to validate an object against **another object**, you simply need to **retrieve the keys** of the second object, using `Object.keys()`, and compare them to the keys of the first object. The rest of the... | [Validate against an array of keys > Validate against another object]
## Validate against another object
If you want to validate an object against **another object**, you simply need to **retrieve the keys** of the second object, using `Object.keys()`, and compare them to the keys of the first object. The rest of the... | code_snippets | ||
6fbc9d90-f40f-4f1f-83b9-3f524410f57c | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/validate-object-properties.md | unknown | 553c0e54-5258-4207-becb-dd92f24b0eb9 | 0 | SemanticChunker@1.0.0 | 94f132f1659388963a5cd8f474c58e08f8985f1a80348ecc08e5894a962148df | ---
title: Validate the properties of a JavaScript object
shortTitle: Validate object properties
language: javascript
tags: [object]
cover: symmetry-cloudy-mountain
excerpt: Check the properties of an object against an array of keys or another object to ensure they match.
listed: true
dateModified: 2024-03-25
---
Chec... | unknown | unknown | ---
title: Validate the properties of a JavaScript object
shortTitle: Validate object properties
language: javascript
tags: [object]
cover: symmetry-cloudy-mountain
excerpt: Check the properties of an object against an array of keys or another object to ensure they match.
listed: true
dateModified: 2024-03-25
---
Chec... | ---
title: Validate the properties of a JavaScript object
shortTitle: Validate object properties
language: javascript
tags: [object]
cover: symmetry-cloudy-mountain
excerpt: Check the properties of an object against an array of keys or another object to ensure they match.
listed: true
dateModified: 2024-03-25
---
Chec... | code_snippets | ||
13e6494a-208a-469b-9b99-5f932af05f32 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/var-let-const.md | unknown | 23590b1e-b604-4d25-8386-25e9d23a28c5 | 4 | SemanticChunker@1.0.0 | 3f5d73c9b31a8bb3892171cc646b81eda6fdab204202e9580a7051b32dde627d | [Scope > Redeclaration]
## Redeclaration
In strict mode, variables declared with `var` can be **re-declared** in the same scope, whereas this is **not allowed** for variables declared with `let` or `const`.
```js
'use strict';
var a = 'var1';
var a = 'var2';
let b = 'let1';
let b = 'let2'; // SyntaxError
```
If yo... | unknown | unknown | [Scope > Redeclaration]
## Redeclaration
In strict mode, variables declared with `var` can be **re-declared** in the same scope, whereas this is **not allowed** for variables declared with `let` or `const`.
```js
'use strict';
var a = 'var1';
var a = 'var2';
let b = 'let1';
let b = 'let2'; // SyntaxError
```
If yo... | [Scope > Redeclaration]
## Redeclaration
In strict mode, variables declared with `var` can be **re-declared** in the same scope, whereas this is **not allowed** for variables declared with `let` or `const`.
```js
'use strict';
var a = 'var1';
var a = 'var2';
let b = 'let1';
let b = 'let2'; // SyntaxError
```
If yo... | code_snippets | ||
17a0b253-322e-4379-8587-09b5cfd2fda5 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/var-let-const.md | unknown | 23590b1e-b604-4d25-8386-25e9d23a28c5 | 0 | SemanticChunker@1.0.0 | 8edcf284126ea7268b7b8c728723a300192a3992b00f98a3962864a0fab15716 | ---
title: What are the differences between var, let and const in JavaScript?
shortTitle: Var, let and const
language: javascript
tags: [type,variable]
cover: green-css
excerpt: JavaScript variables can be declared a handful of ways. However, understanding their differences can drastically change the way you code.
list... | unknown | unknown | ---
title: What are the differences between var, let and const in JavaScript?
shortTitle: Var, let and const
language: javascript
tags: [type,variable]
cover: green-css
excerpt: JavaScript variables can be declared a handful of ways. However, understanding their differences can drastically change the way you code.
list... | ---
title: What are the differences between var, let and const in JavaScript?
shortTitle: Var, let and const
language: javascript
tags: [type,variable]
cover: green-css
excerpt: JavaScript variables can be declared a handful of ways. However, understanding their differences can drastically change the way you code.
list... | code_snippets | ||
23452c7a-f94b-409f-83b1-914f755ddaca | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/var-let-const.md | unknown | 23590b1e-b604-4d25-8386-25e9d23a28c5 | 2 | SemanticChunker@1.0.0 | ae8b5d8e243472f9c74e726dde31113c38f2eb3de9ffa8c42ab2d48121f5ce28 | [Scope > Hoisting]
## Hoisting
While variables declared with `var` are **hoisted** to the enclosing scope, variables declared with `let` or `const` are **not initialized** until their definition is evaluated.
```js
const hoistingExample = () => {
console.log(a); // undefined
var a = 'var';
console.log(a); // 'var... | unknown | unknown | [Scope > Hoisting]
## Hoisting
While variables declared with `var` are **hoisted** to the enclosing scope, variables declared with `let` or `const` are **not initialized** until their definition is evaluated.
```js
const hoistingExample = () => {
console.log(a); // undefined
var a = 'var';
console.log(a); // 'var... | [Scope > Hoisting]
## Hoisting
While variables declared with `var` are **hoisted** to the enclosing scope, variables declared with `let` or `const` are **not initialized** until their definition is evaluated.
```js
const hoistingExample = () => {
console.log(a); // undefined
var a = 'var';
console.log(a); // 'var... | code_snippets | ||
4f83e5ed-622f-4409-8708-41e0e0efe04f | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/var-let-const.md | unknown | 23590b1e-b604-4d25-8386-25e9d23a28c5 | 1 | SemanticChunker@1.0.0 | 376f822e0f1db656f5c2f479ce3a09027e05a0b53e616f5cb47f39c682bd11f5 | [Scope]
## Scope
Variables declared with `var` are **function scoped**, in contrast to variables declared with `let` or `const` which are **block scoped**.
```js
const scopeExample = () => {
var a = 'var';
let b = 'let';
console.log(a, b); // 'var', 'let'
{
var c = 'var';
let d = 'let';
console.log(c, d); //... | unknown | unknown | [Scope]
## Scope
Variables declared with `var` are **function scoped**, in contrast to variables declared with `let` or `const` which are **block scoped**.
```js
const scopeExample = () => {
var a = 'var';
let b = 'let';
console.log(a, b); // 'var', 'let'
{
var c = 'var';
let d = 'let';
console.log(c, d); //... | [Scope]
## Scope
Variables declared with `var` are **function scoped**, in contrast to variables declared with `let` or `const` which are **block scoped**.
```js
const scopeExample = () => {
var a = 'var';
let b = 'let';
console.log(a, b); // 'var', 'let'
{
var c = 'var';
let d = 'let';
console.log(c, d); //... | code_snippets | ||
91ba994e-738c-4f10-ab62-e88807b891d2 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/var-let-const.md | unknown | 23590b1e-b604-4d25-8386-25e9d23a28c5 | 3 | SemanticChunker@1.0.0 | baaa8aa8019bfd9f6029b612bee64769d99c2522d4347d87df4f98be35828303 | [Scope > Global object property]
## Global object property
At the top level, variables declared with `var`, unlike ones declared with `let` or `const`, create a property on the **global object**.
```js
var a = 'var';
let b = 'let';
console.log(window.a); // 'var'
console.log(window.b); // undefined
``` | unknown | unknown | [Scope > Global object property]
## Global object property
At the top level, variables declared with `var`, unlike ones declared with `let` or `const`, create a property on the **global object**.
```js
var a = 'var';
let b = 'let';
console.log(window.a); // 'var'
console.log(window.b); // undefined
``` | [Scope > Global object property]
## Global object property
At the top level, variables declared with `var`, unlike ones declared with `let` or `const`, create a property on the **global object**.
```js
var a = 'var';
let b = 'let';
console.log(window.a); // 'var'
console.log(window.b); // undefined
``` | code_snippets | ||
0e23c140-be1e-4eb6-a58b-003351090df0 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/vocal-fails-silencing-errors.md | unknown | b7988f5a-84f0-4d7d-ac62-bf1c7a98e2e6 | 1 | SemanticChunker@1.0.0 | d5c9e5603b7a8d385dd11915694fed2dbd849a2ed95bc6bdb74a3ea35b33d96c | [The danger of silent fails]
## The danger of silent fails
**Silent fails** occur when errors are caught, but not properly handled or communicated. This can happen in several ways. Let's look at a couple of examples:
```js
fetch('https://api.example.com/data')
.then(response => response.json())
.catch(() => {}); /... | unknown | unknown | [The danger of silent fails]
## The danger of silent fails
**Silent fails** occur when errors are caught, but not properly handled or communicated. This can happen in several ways. Let's look at a couple of examples:
```js
fetch('https://api.example.com/data')
.then(response => response.json())
.catch(() => {}); /... | [The danger of silent fails]
## The danger of silent fails
**Silent fails** occur when errors are caught, but not properly handled or communicated. This can happen in several ways. Let's look at a couple of examples:
```js
fetch('https://api.example.com/data')
.then(response => response.json())
.catch(() => {}); /... | code_snippets | ||
0eca4523-e264-49f3-a972-2fe1fb4efdc8 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/vocal-fails-silencing-errors.md | unknown | b7988f5a-84f0-4d7d-ac62-bf1c7a98e2e6 | 2 | SemanticChunker@1.0.0 | c19a2ae0b0a169fd415f4bbef8b11cc83e7024994dcf5ad7ea0017f32fae6957 | [The danger of silent fails > Failing vocally]
## Failing vocally
Instead of silencing errors, make them **vocal and expressive**. This doesn't mean you should crash your program at every opportunity, but you should ensure errors are logged, communicated, or handled in a way that provides clarity.
One solution is to... | unknown | unknown | [The danger of silent fails > Failing vocally]
## Failing vocally
Instead of silencing errors, make them **vocal and expressive**. This doesn't mean you should crash your program at every opportunity, but you should ensure errors are logged, communicated, or handled in a way that provides clarity.
One solution is to... | [The danger of silent fails > Failing vocally]
## Failing vocally
Instead of silencing errors, make them **vocal and expressive**. This doesn't mean you should crash your program at every opportunity, but you should ensure errors are logged, communicated, or handled in a way that provides clarity.
One solution is to... | code_snippets | ||
4f90c217-0988-4b2c-b9cc-8f90fb5645ef | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/vocal-fails-silencing-errors.md | unknown | b7988f5a-84f0-4d7d-ac62-bf1c7a98e2e6 | 5 | SemanticChunker@1.0.0 | e43fecf06bb106dd7dee32e024736e600066f30d50faff490eb7ddebfb0e17cd | [The danger of silent fails > Conclusion]
## Conclusion
Errors are an essential part of the development process. **Vocal errors** — those that are logged, thrown, or otherwise communicated — make debugging easier, improve collaboration, and lead to better code quality. While there are cases where silencing an error i... | unknown | unknown | [The danger of silent fails > Conclusion]
## Conclusion
Errors are an essential part of the development process. **Vocal errors** — those that are logged, thrown, or otherwise communicated — make debugging easier, improve collaboration, and lead to better code quality. While there are cases where silencing an error i... | [The danger of silent fails > Conclusion]
## Conclusion
Errors are an essential part of the development process. **Vocal errors** — those that are logged, thrown, or otherwise communicated — make debugging easier, improve collaboration, and lead to better code quality. While there are cases where silencing an error i... | code_snippets | ||
55157e93-9b03-4fbf-bbd8-ba31ce0ba113 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/vocal-fails-silencing-errors.md | unknown | b7988f5a-84f0-4d7d-ac62-bf1c7a98e2e6 | 3 | SemanticChunker@1.0.0 | b3f99229e13b30b58981953f2f8141b06c48b3ccbc99feb1584dfe057f7e460d | [The danger of silent fails > Failing vocally]
Here, the error is expected, so we handle it by retrying the fetch operation. If all retries fail, we throw the error again, making it vocal, so that our code can handle it elsewhere. | unknown | unknown | [The danger of silent fails > Failing vocally]
Here, the error is expected, so we handle it by retrying the fetch operation. If all retries fail, we throw the error again, making it vocal, so that our code can handle it elsewhere. | [The danger of silent fails > Failing vocally]
Here, the error is expected, so we handle it by retrying the fetch operation. If all retries fail, we throw the error again, making it vocal, so that our code can handle it elsewhere. | code_snippets | ||
590d64af-0140-4f87-9eb4-2af574853e96 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/vocal-fails-silencing-errors.md | unknown | b7988f5a-84f0-4d7d-ac62-bf1c7a98e2e6 | 0 | SemanticChunker@1.0.0 | 836412d2bb1199577baf76c94278aa5442dfbb247774092033786fd3116e97a3 | ---
title: Vocal fails are better than silent fails
shortTitle: Vocal vs silent fails
language: javascript
tags: [webdev,debugging]
cover: interior-17
excerpt: Learn why vocal errors are better than silent ones, how to handle them effectively, and improve debugging and collaboration in JavaScript.
listed: true
dateModi... | unknown | unknown | ---
title: Vocal fails are better than silent fails
shortTitle: Vocal vs silent fails
language: javascript
tags: [webdev,debugging]
cover: interior-17
excerpt: Learn why vocal errors are better than silent ones, how to handle them effectively, and improve debugging and collaboration in JavaScript.
listed: true
dateModi... | ---
title: Vocal fails are better than silent fails
shortTitle: Vocal vs silent fails
language: javascript
tags: [webdev,debugging]
cover: interior-17
excerpt: Learn why vocal errors are better than silent ones, how to handle them effectively, and improve debugging and collaboration in JavaScript.
listed: true
dateModi... | code_snippets | ||
ad854cce-7fe0-4fc7-9ec1-a49b04ed9357 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/vocal-fails-silencing-errors.md | unknown | b7988f5a-84f0-4d7d-ac62-bf1c7a98e2e6 | 4 | SemanticChunker@1.0.0 | 82616004fa631ac3e9bbd659fa317760a50c6c3e552a8bd86f9cd4693c705329 | [The danger of silent fails > Errors for humans]
## Errors for humans
Errors should be **expressive and helpful**. They're meant to be consumed by humans, not just computers. A good error message communicates **what went wrong** and how to fix it. For machine consumption, differentiating **error classes** (e.g., `Typ... | unknown | unknown | [The danger of silent fails > Errors for humans]
## Errors for humans
Errors should be **expressive and helpful**. They're meant to be consumed by humans, not just computers. A good error message communicates **what went wrong** and how to fix it. For machine consumption, differentiating **error classes** (e.g., `Typ... | [The danger of silent fails > Errors for humans]
## Errors for humans
Errors should be **expressive and helpful**. They're meant to be consumed by humans, not just computers. A good error message communicates **what went wrong** and how to fix it. For machine consumption, differentiating **error classes** (e.g., `Typ... | code_snippets | ||
071e8422-8b29-4bdf-8a3d-d17084636304 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/writing-great-code.md | unknown | 2d354bf7-fc64-4b37-be28-12d78c09d653 | 3 | SemanticChunker@1.0.0 | bd10e4da3d9a5908741fd1c2a9423bbd325a57bda3e57c7f1f740f1bcc6d65a8 | [State is the enemy > Less is more]
## Less is more
**Large functions** are hard to read, test, and maintain. There are plenty of rules of thumb for function size and it really depends on the context, but I strive to keep functions below, say, 20 lines, with the occasional exception. If a function is getting too big,... | unknown | unknown | [State is the enemy > Less is more]
## Less is more
**Large functions** are hard to read, test, and maintain. There are plenty of rules of thumb for function size and it really depends on the context, but I strive to keep functions below, say, 20 lines, with the occasional exception. If a function is getting too big,... | [State is the enemy > Less is more]
## Less is more
**Large functions** are hard to read, test, and maintain. There are plenty of rules of thumb for function size and it really depends on the context, but I strive to keep functions below, say, 20 lines, with the occasional exception. If a function is getting too big,... | code_snippets | ||
43313854-c47c-48ae-86fc-1187eead0724 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/writing-great-code.md | unknown | 2d354bf7-fc64-4b37-be28-12d78c09d653 | 2 | SemanticChunker@1.0.0 | 3d7a9b902b50cc08dad833cfdaf81edf476fac82336369502b9f26e9c25ef6c6 | [State is the enemy > Control your flow]
## Control your flow
**Complex flow control** such as deeply nested `if` statements, or loops within loops, make code hard to follow and even harder to test. A simple example of **nested logic** can look something like the following.
```js
const processOrder = order => {
if ... | unknown | unknown | [State is the enemy > Control your flow]
## Control your flow
**Complex flow control** such as deeply nested `if` statements, or loops within loops, make code hard to follow and even harder to test. A simple example of **nested logic** can look something like the following.
```js
const processOrder = order => {
if ... | [State is the enemy > Control your flow]
## Control your flow
**Complex flow control** such as deeply nested `if` statements, or loops within loops, make code hard to follow and even harder to test. A simple example of **nested logic** can look something like the following.
```js
const processOrder = order => {
if ... | code_snippets | ||
57ac506a-b7dd-4998-893e-8f7c290715e1 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/writing-great-code.md | unknown | 2d354bf7-fc64-4b37-be28-12d78c09d653 | 5 | SemanticChunker@1.0.0 | 35902f394f418187c2fdc8659300318aadc5cb2b45627510f89feb7fae55ed0f | [State is the enemy > Even tests need good code]
## Even tests need good code
It's **nearly impossible to write good tests for bad code**. If your code is a tangled mess of hidden state, mixed responsibilities and complicated logic, testing becomes an uphill battle. As a rule of thumb, write code as if you will need ... | unknown | unknown | [State is the enemy > Even tests need good code]
## Even tests need good code
It's **nearly impossible to write good tests for bad code**. If your code is a tangled mess of hidden state, mixed responsibilities and complicated logic, testing becomes an uphill battle. As a rule of thumb, write code as if you will need ... | [State is the enemy > Even tests need good code]
## Even tests need good code
It's **nearly impossible to write good tests for bad code**. If your code is a tangled mess of hidden state, mixed responsibilities and complicated logic, testing becomes an uphill battle. As a rule of thumb, write code as if you will need ... | code_snippets | ||
a3710eee-7573-491a-91cc-a2c4bb9a2ad0 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/writing-great-code.md | unknown | 2d354bf7-fc64-4b37-be28-12d78c09d653 | 4 | SemanticChunker@1.0.0 | 3326aa783619d96c4e8ef661ce7fe0d0d20fa0f53b4cc279a431aa3f7ccca1c5 | [State is the enemy > Be responsible for one thing]
## Be responsible for one thing
A function should do one thing, and do it well. If a function does two things, break it down. For example, the following function violates the **Single Responsibility Principle (SRP)** by mixing validation and saving logic:
```js
con... | unknown | unknown | [State is the enemy > Be responsible for one thing]
## Be responsible for one thing
A function should do one thing, and do it well. If a function does two things, break it down. For example, the following function violates the **Single Responsibility Principle (SRP)** by mixing validation and saving logic:
```js
con... | [State is the enemy > Be responsible for one thing]
## Be responsible for one thing
A function should do one thing, and do it well. If a function does two things, break it down. For example, the following function violates the **Single Responsibility Principle (SRP)** by mixing validation and saving logic:
```js
con... | code_snippets | ||
d82813f3-c2ae-4010-b330-4539032308fc | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/writing-great-code.md | unknown | 2d354bf7-fc64-4b37-be28-12d78c09d653 | 1 | SemanticChunker@1.0.0 | b2c866a2c04187cba07ba671a9a898690e8eb35a5983ec4a852feaa1e24dc6d1 | [State is the enemy]
## State is the enemy
State is at the heart of many bugs and headaches. Poor **state management** considerations can often lead to unexpected results and make your code hard to reason about, maintain and test.
**Mutable state** is one of, if not the most, common source of bugs. Try to **avoid it... | unknown | unknown | [State is the enemy]
## State is the enemy
State is at the heart of many bugs and headaches. Poor **state management** considerations can often lead to unexpected results and make your code hard to reason about, maintain and test.
**Mutable state** is one of, if not the most, common source of bugs. Try to **avoid it... | [State is the enemy]
## State is the enemy
State is at the heart of many bugs and headaches. Poor **state management** considerations can often lead to unexpected results and make your code hard to reason about, maintain and test.
**Mutable state** is one of, if not the most, common source of bugs. Try to **avoid it... | code_snippets | ||
deb11dab-61ab-47dd-8f70-5e375248f02e | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/writing-great-code.md | unknown | 2d354bf7-fc64-4b37-be28-12d78c09d653 | 6 | SemanticChunker@1.0.0 | 5db4ab69d255509a17554fa1075d8f10ad3076dcc2158fee016b58dbe65615a0 | [State is the enemy > Conclusion]
## Conclusion
Writing great code is about more than making things work. It's about making your code easy to read, maintain, and test. Manage state carefully, keep your functions small and focused, avoid hidden dependencies, and always strive for clarity. By following these simple pri... | unknown | unknown | [State is the enemy > Conclusion]
## Conclusion
Writing great code is about more than making things work. It's about making your code easy to read, maintain, and test. Manage state carefully, keep your functions small and focused, avoid hidden dependencies, and always strive for clarity. By following these simple pri... | [State is the enemy > Conclusion]
## Conclusion
Writing great code is about more than making things work. It's about making your code easy to read, maintain, and test. Manage state carefully, keep your functions small and focused, avoid hidden dependencies, and always strive for clarity. By following these simple pri... | code_snippets | ||
e7e65ce7-c1a4-4c25-8ff3-d39b39d8b2b6 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/writing-great-code.md | unknown | 2d354bf7-fc64-4b37-be28-12d78c09d653 | 0 | SemanticChunker@1.0.0 | 2345b7923e6f06bcd1e3ff1ccbbf455daa2cbfa5648421d4d0cd8c9ec2c51be4 | ---
title: The art of writing great code
shortTitle: Writing great code
language: javascript
tags: [webdev,career,programming,jobs]
cover: coffee-drip-2
excerpt: Writing great code is more than writing code that works, requiring discipline and a focus on testability, maintainability, and readability.
listed: true
dateM... | unknown | unknown | ---
title: The art of writing great code
shortTitle: Writing great code
language: javascript
tags: [webdev,career,programming,jobs]
cover: coffee-drip-2
excerpt: Writing great code is more than writing code that works, requiring discipline and a focus on testability, maintainability, and readability.
listed: true
dateM... | ---
title: The art of writing great code
shortTitle: Writing great code
language: javascript
tags: [webdev,career,programming,jobs]
cover: coffee-drip-2
excerpt: Writing great code is more than writing code that works, requiring discipline and a focus on testability, maintainability, and readability.
listed: true
dateM... | code_snippets | ||
0bb1d48a-7b8d-4b33-b473-d69f55f9ebaf | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/zip-unzip-array.md | unknown | f6441893-d696-4251-ae43-34246ce3e988 | 3 | SemanticChunker@1.0.0 | b70fb9271cd0c667af4f9618e63a25c27d806cd0ca3d704a44df86d21d8d64d2 | [Zip arrays > Zip array into object]
## Zip array into object
If you want to zip an array into an object, you can use a similar technique to the one used for zipping arrays. The only difference is that you need to use `Array.prototype.reduce()` to **assign the key-value pairs** to the object.
```js
const zipObject =... | unknown | unknown | [Zip arrays > Zip array into object]
## Zip array into object
If you want to zip an array into an object, you can use a similar technique to the one used for zipping arrays. The only difference is that you need to use `Array.prototype.reduce()` to **assign the key-value pairs** to the object.
```js
const zipObject =... | [Zip arrays > Zip array into object]
## Zip array into object
If you want to zip an array into an object, you can use a similar technique to the one used for zipping arrays. The only difference is that you need to use `Array.prototype.reduce()` to **assign the key-value pairs** to the object.
```js
const zipObject =... | code_snippets | ||
4e4be40e-3571-45e9-be57-7c429b56e107 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/zip-unzip-array.md | unknown | f6441893-d696-4251-ae43-34246ce3e988 | 4 | SemanticChunker@1.0.0 | ebb70243b3cc97c863d1fb1e04ee9bedd86a1cadd4d07003a6edcc9fd7eefc4a | [Zip arrays > Unzip object into array]
## Unzip object into array
Unzipping an object into a pair of arrays is quite simple. You can use `Object.keys()` and `Object.values()` to **get the keys and values** of the object as arrays.
```js
const unzipObject = obj => [
Object.keys(obj),
Object.values(obj)
];
unzipObj... | unknown | unknown | [Zip arrays > Unzip object into array]
## Unzip object into array
Unzipping an object into a pair of arrays is quite simple. You can use `Object.keys()` and `Object.values()` to **get the keys and values** of the object as arrays.
```js
const unzipObject = obj => [
Object.keys(obj),
Object.values(obj)
];
unzipObj... | [Zip arrays > Unzip object into array]
## Unzip object into array
Unzipping an object into a pair of arrays is quite simple. You can use `Object.keys()` and `Object.values()` to **get the keys and values** of the object as arrays.
```js
const unzipObject = obj => [
Object.keys(obj),
Object.values(obj)
];
unzipObj... | code_snippets | ||
71b70ba7-58da-4f9d-8152-6ce8993f4a19 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/zip-unzip-array.md | unknown | f6441893-d696-4251-ae43-34246ce3e988 | 0 | SemanticChunker@1.0.0 | d3fea57befd99ec7cf4f8e4dfc68d55570e91ba6ed028f8c6b8764eb36663d86 | ---
title: How can I zip and unzip arrays in JavaScript?
shortTitle: Zip or unzip arrays
language: javascript
tags: [array]
cover: new-york-skyline
excerpt: Learn how to implement array zipping, a grouping of elements based on position in the original arrays, and its inverse, unzipping.
listed: true
dateModified: 2024-... | unknown | unknown | ---
title: How can I zip and unzip arrays in JavaScript?
shortTitle: Zip or unzip arrays
language: javascript
tags: [array]
cover: new-york-skyline
excerpt: Learn how to implement array zipping, a grouping of elements based on position in the original arrays, and its inverse, unzipping.
listed: true
dateModified: 2024-... | ---
title: How can I zip and unzip arrays in JavaScript?
shortTitle: Zip or unzip arrays
language: javascript
tags: [array]
cover: new-york-skyline
excerpt: Learn how to implement array zipping, a grouping of elements based on position in the original arrays, and its inverse, unzipping.
listed: true
dateModified: 2024-... | code_snippets | ||
80e92ed0-c64c-4152-9b91-916945d0e624 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/zip-unzip-array.md | unknown | f6441893-d696-4251-ae43-34246ce3e988 | 2 | SemanticChunker@1.0.0 | 350f45af5f2f77eec53bafba0015e74b5e9b8a8282e370c45a35be460cb58851 | [Zip arrays > Unzip arrays]
## Unzip arrays
The inverse of zipping is unzipping, which converts the array of arrays back into separate arrays. We can use `Math.max()` and the spread operator (`...`) to get the **longest subarray** in the array and `Array.from()` to create an array of appropriate length.
Then, using ... | unknown | unknown | [Zip arrays > Unzip arrays]
## Unzip arrays
The inverse of zipping is unzipping, which converts the array of arrays back into separate arrays. We can use `Math.max()` and the spread operator (`...`) to get the **longest subarray** in the array and `Array.from()` to create an array of appropriate length.
Then, using ... | [Zip arrays > Unzip arrays]
## Unzip arrays
The inverse of zipping is unzipping, which converts the array of arrays back into separate arrays. We can use `Math.max()` and the spread operator (`...`) to get the **longest subarray** in the array and `Array.from()` to create an array of appropriate length.
Then, using ... | code_snippets | ||
9ffa76cd-95d7-40e9-96f3-15cdeb059c0d | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/zip-unzip-array.md | unknown | f6441893-d696-4251-ae43-34246ce3e988 | 1 | SemanticChunker@1.0.0 | 6959cbf3f29662789da6e12c08c0cbfa88a29b8a5ad55079fac4c0603fd2ccaa | [Zip arrays]
## Zip arrays
Zipping requires the creation of an array with the **length of the longest array** in the arguments. We can use `Math.max()` and the spread operator (`...`) to get the longest subarray in the array and `Array.from()` to create an array of appropriate length.
Then, using `Array.prototype.ma... | unknown | unknown | [Zip arrays]
## Zip arrays
Zipping requires the creation of an array with the **length of the longest array** in the arguments. We can use `Math.max()` and the spread operator (`...`) to get the longest subarray in the array and `Array.from()` to create an array of appropriate length.
Then, using `Array.prototype.ma... | [Zip arrays]
## Zip arrays
Zipping requires the creation of an array with the **length of the longest array** in the arguments. We can use `Math.max()` and the spread operator (`...`) to get the longest subarray in the array and `Array.from()` to create an array of appropriate length.
Then, using `Array.prototype.ma... | code_snippets | ||
f890e512-5092-4030-8731-7d692cc3443a | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/yes-no.md | unknown | 8b8f4028-45a3-4f65-b279-91e3baebf1bc | 0 | SemanticChunker@1.0.0 | e68a313bc8fcc3904d04ab41a91390aac4a31870e431549b958e9258ebe0a33c | ---
title: Check if a string is a yes/no answer with JavaScript
shortTitle: Yes/no answer
language: javascript
tags: [string,regexp]
cover: fort-lamp
excerpt: Quickly and easily check if a string is a yes/no answer to a boolean question in your CLI programs.
listed: true
dateModified: 2023-12-15
---
If you've spent an... | unknown | unknown | ---
title: Check if a string is a yes/no answer with JavaScript
shortTitle: Yes/no answer
language: javascript
tags: [string,regexp]
cover: fort-lamp
excerpt: Quickly and easily check if a string is a yes/no answer to a boolean question in your CLI programs.
listed: true
dateModified: 2023-12-15
---
If you've spent an... | ---
title: Check if a string is a yes/no answer with JavaScript
shortTitle: Yes/no answer
language: javascript
tags: [string,regexp]
cover: fort-lamp
excerpt: Quickly and easily check if a string is a yes/no answer to a boolean question in your CLI programs.
listed: true
dateModified: 2023-12-15
---
If you've spent an... | code_snippets | ||
1f35c402-68c4-4d84-9920-1907f7475316 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/word-wrap.md | unknown | f90b419d-1a1b-4d92-805d-4754b64e1d8f | 0 | SemanticChunker@1.0.0 | 149986d7c6e6720bd75bf9c038b04c7971064c5218e948723856c84fab3bcbee | ---
title: Word wrap a JavaScrip string
shortTitle: Word wrap
language: javascript
tags: [string,regexp]
cover: white-tablet
excerpt: Wrap a string to a given number of characters using a string break character in JavaScript.
listed: true
dateModified: 2024-02-29
---
Text wrapping isn't the easiest thing to do, especi... | unknown | unknown | ---
title: Word wrap a JavaScrip string
shortTitle: Word wrap
language: javascript
tags: [string,regexp]
cover: white-tablet
excerpt: Wrap a string to a given number of characters using a string break character in JavaScript.
listed: true
dateModified: 2024-02-29
---
Text wrapping isn't the easiest thing to do, especi... | ---
title: Word wrap a JavaScrip string
shortTitle: Word wrap
language: javascript
tags: [string,regexp]
cover: white-tablet
excerpt: Wrap a string to a given number of characters using a string break character in JavaScript.
listed: true
dateModified: 2024-02-29
---
Text wrapping isn't the easiest thing to do, especi... | code_snippets | ||
9a8f8725-82a9-45a5-b5d7-7eeaba5bd8e8 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/word-wrap.md | unknown | f90b419d-1a1b-4d92-805d-4754b64e1d8f | 1 | SemanticChunker@1.0.0 | f98b1f07a81319ef873935e74fc1f94fae184b5f20c420a07aa4491b7dbeea3f | In order to make this more generic, we can use the `RegExp()` constructor to create a regular expression with a **dynamic maximum length**. This allows us to create a function that can word wrap a string to any number of characters.
```js
const wordWrap = (str, max, br = '\n') => str.replace(
new RegExp(`(?![^\\n]{1,... | unknown | unknown | In order to make this more generic, we can use the `RegExp()` constructor to create a regular expression with a **dynamic maximum length**. This allows us to create a function that can word wrap a string to any number of characters.
```js
const wordWrap = (str, max, br = '\n') => str.replace(
new RegExp(`(?![^\\n]{1,... | In order to make this more generic, we can use the `RegExp()` constructor to create a regular expression with a **dynamic maximum length**. This allows us to create a function that can word wrap a string to any number of characters.
```js
const wordWrap = (str, max, br = '\n') => str.replace(
new RegExp(`(?![^\\n]{1,... | code_snippets | ||
65a4583d-7db2-4224-a5c0-fae1b9ffdd43 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/window-location-cheatsheet.md | unknown | 805a6d66-08fd-4995-a67e-ee1f61c8e941 | 0 | SemanticChunker@1.0.0 | b14d1cf259b437820fe3c82fb5f930eb54150b952440c45378405b8b188787a0 | ---
title: Window.location Cheat Sheet
language: javascript
tags: [browser,cheatsheet]
cover: yellow-sofa
excerpt: A quick reference for the `window.location` object.
listed: true
dateModified: 2022-12-21
---
The `window.location` object is particularly useful when **working with a page's URL information**. Let's take... | unknown | unknown | ---
title: Window.location Cheat Sheet
language: javascript
tags: [browser,cheatsheet]
cover: yellow-sofa
excerpt: A quick reference for the `window.location` object.
listed: true
dateModified: 2022-12-21
---
The `window.location` object is particularly useful when **working with a page's URL information**. Let's take... | ---
title: Window.location Cheat Sheet
language: javascript
tags: [browser,cheatsheet]
cover: yellow-sofa
excerpt: A quick reference for the `window.location` object.
listed: true
dateModified: 2022-12-21
---
The `window.location` object is particularly useful when **working with a page's URL information**. Let's take... | code_snippets | ||
dcb460ed-4ef2-4ab7-b327-fdfb641a8d23 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/window-location-cheatsheet.md | unknown | 805a6d66-08fd-4995-a67e-ee1f61c8e941 | 1 | SemanticChunker@1.0.0 | 9d7aa8846b90073cb3638f3ff88fe9983a654e24c4432828b78a0f9b0b61e678 | [window.location.protocol > window.location.href]
## window.location.href
- The full URL, including the protocol schema, domain name, port number, path, query string and fragment identifier
- Sample value: `https://dev.30secondsofcode.org:8000/c/js?page=2&sort=asc#search` | unknown | unknown | [window.location.protocol > window.location.href]
## window.location.href
- The full URL, including the protocol schema, domain name, port number, path, query string and fragment identifier
- Sample value: `https://dev.30secondsofcode.org:8000/c/js?page=2&sort=asc#search` | [window.location.protocol > window.location.href]
## window.location.href
- The full URL, including the protocol schema, domain name, port number, path, query string and fragment identifier
- Sample value: `https://dev.30secondsofcode.org:8000/c/js?page=2&sort=asc#search` | code_snippets | ||
34db2b6b-e647-4e43-882a-2894f2a04d41 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/python/s/bare-except.md | unknown | 6b85b521-bec2-474d-b1cf-480aa59d5a40 | 0 | SemanticChunker@1.0.0 | 067e8bd7d66e7500a91f185fdf6474f094725cb9f59f365d27ec2bfadc64a319 | ---
title: Avoid using bare except in Python
shortTitle: Bare except best practices
language: python
tags: [error]
cover: dark-cloud
excerpt: It's generally not a good idea to use bare `except` clause in Python, but do you know why?
listed: false
dateModified: 2022-02-20
---
In Python, keyboard interrupts and system e... | unknown | unknown | ---
title: Avoid using bare except in Python
shortTitle: Bare except best practices
language: python
tags: [error]
cover: dark-cloud
excerpt: It's generally not a good idea to use bare `except` clause in Python, but do you know why?
listed: false
dateModified: 2022-02-20
---
In Python, keyboard interrupts and system e... | ---
title: Avoid using bare except in Python
shortTitle: Bare except best practices
language: python
tags: [error]
cover: dark-cloud
excerpt: It's generally not a good idea to use bare `except` clause in Python, but do you know why?
listed: false
dateModified: 2022-02-20
---
In Python, keyboard interrupts and system e... | code_snippets | ||
0678a39a-06fb-4213-840e-08c7c3f3f019 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/python/s/6-f-strings-tips.md | unknown | ae52c91e-f696-40de-9b8f-cbdd93f42b9e | 0 | SemanticChunker@1.0.0 | 46c4a7e9e230cd51e8573705a2df8820bdb7883cd5f3a2b9da9125c19830ac9c | ---
title: 6 Python f-strings tips and tricks
language: python
tags: [string]
cover: sea-view
excerpt: Python's f-strings can do a lot more than you might expect. Learn a few useful tips and tricks in this quick guide.
listed: false
dateModified: 2021-07-20
---
Python's f-strings provide a more readable, concise and l... | unknown | unknown | ---
title: 6 Python f-strings tips and tricks
language: python
tags: [string]
cover: sea-view
excerpt: Python's f-strings can do a lot more than you might expect. Learn a few useful tips and tricks in this quick guide.
listed: false
dateModified: 2021-07-20
---
Python's f-strings provide a more readable, concise and l... | ---
title: 6 Python f-strings tips and tricks
language: python
tags: [string]
cover: sea-view
excerpt: Python's f-strings can do a lot more than you might expect. Learn a few useful tips and tricks in this quick guide.
listed: false
dateModified: 2021-07-20
---
Python's f-strings provide a more readable, concise and l... | code_snippets | ||
33385ebb-be0c-458f-ad51-0cb093f3886e | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/python/s/6-f-strings-tips.md | unknown | ae52c91e-f696-40de-9b8f-cbdd93f42b9e | 6 | SemanticChunker@1.0.0 | 00fb242e36b42e9df7af21d9f6d6f57e8117e0d63c616239a44ed16c0e37141d | [String Interpolation > Date formatting]
## Date formatting
Finally, dates can also be formatted the same way as numbers, using format specifiers. As usual, `%Y` denotes the full year, `%m` is the month and `%d` is the day of the month.
```py
from datetime import datetime;
date_val = datetime.utcnow()
print(f'{dat... | unknown | unknown | [String Interpolation > Date formatting]
## Date formatting
Finally, dates can also be formatted the same way as numbers, using format specifiers. As usual, `%Y` denotes the full year, `%m` is the month and `%d` is the day of the month.
```py
from datetime import datetime;
date_val = datetime.utcnow()
print(f'{dat... | [String Interpolation > Date formatting]
## Date formatting
Finally, dates can also be formatted the same way as numbers, using format specifiers. As usual, `%Y` denotes the full year, `%m` is the month and `%d` is the day of the month.
```py
from datetime import datetime;
date_val = datetime.utcnow()
print(f'{dat... | code_snippets | ||
55df26aa-384e-4d03-ad48-dff2af5f1019 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/python/s/6-f-strings-tips.md | unknown | ae52c91e-f696-40de-9b8f-cbdd93f42b9e | 2 | SemanticChunker@1.0.0 | 8aeea4b09dceb6bdba93cc2fac437dcd70198c47edc59bccf8c020cb52620fdd | [String Interpolation > Variable names]
## Variable names
Apart from getting a variable's value, you can also get its name alongside the value. This can be especially useful when debugging and can be easily accomplished by adding an equals sign (`=`) after the variable name inside the curly braces.
Bear in mind that... | unknown | unknown | [String Interpolation > Variable names]
## Variable names
Apart from getting a variable's value, you can also get its name alongside the value. This can be especially useful when debugging and can be easily accomplished by adding an equals sign (`=`) after the variable name inside the curly braces.
Bear in mind that... | [String Interpolation > Variable names]
## Variable names
Apart from getting a variable's value, you can also get its name alongside the value. This can be especially useful when debugging and can be easily accomplished by adding an equals sign (`=`) after the variable name inside the curly braces.
Bear in mind that... | code_snippets | ||
56e30af0-f7f8-4386-bd56-80f34353021f | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/python/s/6-f-strings-tips.md | unknown | ae52c91e-f696-40de-9b8f-cbdd93f42b9e | 4 | SemanticChunker@1.0.0 | 948bcf979c06d29cbbb3d854d3718c3235d1ca8c41e44261ec0d71f209f6ed61 | [String Interpolation > Printable representation]
## Printable representation
Apart from plain string interpolation, you might want to get the printable representation of a value. This is already easy to accomplish using the `repr()` function. f-strings provide a much shorter syntax by appending a `!r` inside the cur... | unknown | unknown | [String Interpolation > Printable representation]
## Printable representation
Apart from plain string interpolation, you might want to get the printable representation of a value. This is already easy to accomplish using the `repr()` function. f-strings provide a much shorter syntax by appending a `!r` inside the cur... | [String Interpolation > Printable representation]
## Printable representation
Apart from plain string interpolation, you might want to get the printable representation of a value. This is already easy to accomplish using the `repr()` function. f-strings provide a much shorter syntax by appending a `!r` inside the cur... | code_snippets | ||
872a8d5d-b38f-4c7f-a097-735076c36a72 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/python/s/6-f-strings-tips.md | unknown | ae52c91e-f696-40de-9b8f-cbdd93f42b9e | 1 | SemanticChunker@1.0.0 | 98dbb1d74788b73eb744f197dbc8210b86ff5a26ffadd9fc7440397fcde6d540 | [String Interpolation]
## String Interpolation
The most used f-string feature by far is string interpolation. All you need to do is wrap the value or variable in curly braces (`{}`) and you're good to go.
```py
str_val = 'apples'
num_val = 42
print(f'{num_val} {str_val}') # 42 apples
``` | unknown | unknown | [String Interpolation]
## String Interpolation
The most used f-string feature by far is string interpolation. All you need to do is wrap the value or variable in curly braces (`{}`) and you're good to go.
```py
str_val = 'apples'
num_val = 42
print(f'{num_val} {str_val}') # 42 apples
``` | [String Interpolation]
## String Interpolation
The most used f-string feature by far is string interpolation. All you need to do is wrap the value or variable in curly braces (`{}`) and you're good to go.
```py
str_val = 'apples'
num_val = 42
print(f'{num_val} {str_val}') # 42 apples
``` | code_snippets | ||
8bbbcd6a-20db-4235-b3c0-3bb2d57a081c | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/python/s/6-f-strings-tips.md | unknown | ae52c91e-f696-40de-9b8f-cbdd93f42b9e | 5 | SemanticChunker@1.0.0 | 19034f691f65dfc112fba50c31d3f013f72987bd0bd8fd7d747192bb08c2374d | [String Interpolation > Number formatting]
## Number formatting
Additionally, f-strings can also be used for formatting - hence the **f** in the name. To add formatting to a value you can add a colon (`:`) followed by a format specifier. This can also be combined with the equals sing from before, shall you want to pr... | unknown | unknown | [String Interpolation > Number formatting]
## Number formatting
Additionally, f-strings can also be used for formatting - hence the **f** in the name. To add formatting to a value you can add a colon (`:`) followed by a format specifier. This can also be combined with the equals sing from before, shall you want to pr... | [String Interpolation > Number formatting]
## Number formatting
Additionally, f-strings can also be used for formatting - hence the **f** in the name. To add formatting to a value you can add a colon (`:`) followed by a format specifier. This can also be combined with the equals sing from before, shall you want to pr... | code_snippets | ||
95c0db58-9bbe-4677-8e0f-8ac0a7832727 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/python/s/6-f-strings-tips.md | unknown | ae52c91e-f696-40de-9b8f-cbdd93f42b9e | 3 | SemanticChunker@1.0.0 | c385c1d79ad8f148b051cb743c26a9213dd8d2b8b5544d7e926ab13e482be8b2 | [String Interpolation > Mathematical operations]
## Mathematical operations
Not syntactically unlike variable names, you can also perform mathematical operations in f-strings. You can place the mathematical expression inside the curly braces and, if you add an equal sign, you'll get the expression and its result.
``... | unknown | unknown | [String Interpolation > Mathematical operations]
## Mathematical operations
Not syntactically unlike variable names, you can also perform mathematical operations in f-strings. You can place the mathematical expression inside the curly braces and, if you add an equal sign, you'll get the expression and its result.
``... | [String Interpolation > Mathematical operations]
## Mathematical operations
Not syntactically unlike variable names, you can also perform mathematical operations in f-strings. You can place the mathematical expression inside the curly braces and, if you add an equal sign, you'll get the expression and its result.
``... | code_snippets | ||
191523e1-c38f-47f2-bfa1-dd8970b12be5 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/python/s/binomial-coefficient.md | unknown | 8c177b6c-5d34-4703-908e-655231953f55 | 0 | SemanticChunker@1.0.0 | 148be1b5ba2323a1a8e87b6bf28ccf821ce7669747322b30c44f18ddde5d186e | ---
title: Binomial coefficient
language: python
tags: [math]
cover: digital-nomad-5
excerpt: Calculate the number of ways to choose `k` items from `n` items without repetition and without order.
listed: false
dateModified: 2024-05-09
---
The binomial coefficient is the number of ways to choose `k` items from `n` item... | unknown | unknown | ---
title: Binomial coefficient
language: python
tags: [math]
cover: digital-nomad-5
excerpt: Calculate the number of ways to choose `k` items from `n` items without repetition and without order.
listed: false
dateModified: 2024-05-09
---
The binomial coefficient is the number of ways to choose `k` items from `n` item... | ---
title: Binomial coefficient
language: python
tags: [math]
cover: digital-nomad-5
excerpt: Calculate the number of ways to choose `k` items from `n` items without repetition and without order.
listed: false
dateModified: 2024-05-09
---
The binomial coefficient is the number of ways to choose `k` items from `n` item... | code_snippets | ||
1d10e136-3e1a-48ef-98f5-9dc6bf847fb9 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/weekday-name.md | unknown | 5310cd5b-0d1f-4e5c-a903-a97d1b7ea7b8 | 2 | SemanticChunker@1.0.0 | a3eb0463f7fc71bb81c0e67bbde62d378bee0af084cb3a6ab90b2c51bc24e09c | [Full weekday name > Short weekday name]
## Short weekday name
Similarly, you can get the **short name** of the weekday by using the [`{ weekday: 'short' }`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat#short) option. This will return the abbrevia... | unknown | unknown | [Full weekday name > Short weekday name]
## Short weekday name
Similarly, you can get the **short name** of the weekday by using the [`{ weekday: 'short' }`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat#short) option. This will return the abbrevia... | [Full weekday name > Short weekday name]
## Short weekday name
Similarly, you can get the **short name** of the weekday by using the [`{ weekday: 'short' }`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat#short) option. This will return the abbrevia... | code_snippets | ||
571b4891-9760-43d1-97b8-0b0b515c0840 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/weekday-name.md | unknown | 5310cd5b-0d1f-4e5c-a903-a97d1b7ea7b8 | 0 | SemanticChunker@1.0.0 | 26d3c2f58d8fc6bffe786e8c39138dcc8be81a2234949a84b5c8802154717cbe | ---
title: Weekday name from a JavaScript Date object
shortTitle: Weekday name
language: javascript
tags: [date]
cover: interior
excerpt: Get the name of the weekday from a JavaScript `Date` object.
listed: true
dateModified: 2024-05-21
---
`Date` objects in JavaScript have a lot of useful methods, even though they of... | unknown | unknown | ---
title: Weekday name from a JavaScript Date object
shortTitle: Weekday name
language: javascript
tags: [date]
cover: interior
excerpt: Get the name of the weekday from a JavaScript `Date` object.
listed: true
dateModified: 2024-05-21
---
`Date` objects in JavaScript have a lot of useful methods, even though they of... | ---
title: Weekday name from a JavaScript Date object
shortTitle: Weekday name
language: javascript
tags: [date]
cover: interior
excerpt: Get the name of the weekday from a JavaScript `Date` object.
listed: true
dateModified: 2024-05-21
---
`Date` objects in JavaScript have a lot of useful methods, even though they of... | code_snippets | ||
aca76368-2b14-443c-be1e-01145608590f | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/weekday-name.md | unknown | 5310cd5b-0d1f-4e5c-a903-a97d1b7ea7b8 | 3 | SemanticChunker@1.0.0 | b263705d1a0659c361da29e9d106f7234dc1ce845c9954a7b6616dcabfde6f4e | [Full weekday name > Single-letter weekday name]
## Single-letter weekday name
If you only need the **first letter** of the weekday name, you can use the [`{ weekday: 'narrow' }`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat#narrow) option. Note t... | unknown | unknown | [Full weekday name > Single-letter weekday name]
## Single-letter weekday name
If you only need the **first letter** of the weekday name, you can use the [`{ weekday: 'narrow' }`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat#narrow) option. Note t... | [Full weekday name > Single-letter weekday name]
## Single-letter weekday name
If you only need the **first letter** of the weekday name, you can use the [`{ weekday: 'narrow' }`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat#narrow) option. Note t... | code_snippets | ||
b11e35b3-c299-4035-9751-af016c354345 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/weekday-name.md | unknown | 5310cd5b-0d1f-4e5c-a903-a97d1b7ea7b8 | 1 | SemanticChunker@1.0.0 | f8699bf779c8e1ddafabeeb05c90802962913e4d8a2a424f8cbe295b8d91e950 | [Full weekday name]
## Full weekday name
To get the **full name** of the weekday, you can use the [`{ weekday: 'long' }`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat#long) option with `Date.prototype.toLocaleDateString()`. If you want to get the ... | unknown | unknown | [Full weekday name]
## Full weekday name
To get the **full name** of the weekday, you can use the [`{ weekday: 'long' }`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat#long) option with `Date.prototype.toLocaleDateString()`. If you want to get the ... | [Full weekday name]
## Full weekday name
To get the **full name** of the weekday, you can use the [`{ weekday: 'long' }`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat#long) option with `Date.prototype.toLocaleDateString()`. If you want to get the ... | code_snippets | ||
5ecdb004-256a-4ef7-ae49-46d8ee72e322 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/snippet-template.md | unknown | f42d42d2-eb48-4600-9cff-521492e9fe9b | 0 | SemanticChunker@1.0.0 | 7841b99d8dad5f89af0adfc6d07e1cf090051586d27570c7a2fbc42c93106454 | ---
title: My amazing story
shortTitle: Amazing story
language: javascript
tags: [array]
cover: image
excerpt: A short summary of your story up to 140 characters long.
listed: true
dateModified: 2021-06-13
---
Write your story here. | unknown | unknown | ---
title: My amazing story
shortTitle: Amazing story
language: javascript
tags: [array]
cover: image
excerpt: A short summary of your story up to 140 characters long.
listed: true
dateModified: 2021-06-13
---
Write your story here. | ---
title: My amazing story
shortTitle: Amazing story
language: javascript
tags: [array]
cover: image
excerpt: A short summary of your story up to 140 characters long.
listed: true
dateModified: 2021-06-13
---
Write your story here. | code_snippets | ||
97e39631-cfe9-461f-886c-6dc7a03248e9 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/python/s/dict-getkey-vs-dictkey.md | unknown | 0853055b-1f97-40f0-86e0-02e84692b48f | 0 | SemanticChunker@1.0.0 | d22a5d2d690b73fb10a66781e0c6f1d66a857662b9133389c0fab34890b2d8cd | ---
title: You should use dict.get(key) instead of dict[key]
shortTitle: dict.get(key) vs dict[key]
language: python
tags: [dictionary]
cover: compass-2
excerpt: Learn the difference between two common ways to access values in Python dictionaries and level up your code today.
listed: false
dateModified: 2021-06-12
---
... | unknown | unknown | ---
title: You should use dict.get(key) instead of dict[key]
shortTitle: dict.get(key) vs dict[key]
language: python
tags: [dictionary]
cover: compass-2
excerpt: Learn the difference between two common ways to access values in Python dictionaries and level up your code today.
listed: false
dateModified: 2021-06-12
---
... | ---
title: You should use dict.get(key) instead of dict[key]
shortTitle: dict.get(key) vs dict[key]
language: python
tags: [dictionary]
cover: compass-2
excerpt: Learn the difference between two common ways to access values in Python dictionaries and level up your code today.
listed: false
dateModified: 2021-06-12
---
... | code_snippets | ||
3ce7aedb-7e65-4fbf-a4bc-1e14fd821213 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/python/s/dictionary-to-list.md | unknown | 4085b1cb-9dd0-4edd-8dec-9ba2c82d946d | 0 | SemanticChunker@1.0.0 | c5599fb07de879cf1e488f6dd29cc6cfe702e51f560974ef8b0680fd970cbcc3 | ---
title: Convert between lists and dictionaries
shortTitle: List to dictionary
language: python
tags: [dictionary,list]
cover: new-york
excerpt: Convert a dictionary to a list of tuples and vice versa.
listed: false
dateModified: 2024-07-04
--- | unknown | unknown | ---
title: Convert between lists and dictionaries
shortTitle: List to dictionary
language: python
tags: [dictionary,list]
cover: new-york
excerpt: Convert a dictionary to a list of tuples and vice versa.
listed: false
dateModified: 2024-07-04
--- | ---
title: Convert between lists and dictionaries
shortTitle: List to dictionary
language: python
tags: [dictionary,list]
cover: new-york
excerpt: Convert a dictionary to a list of tuples and vice versa.
listed: false
dateModified: 2024-07-04
--- | code_snippets | ||
66bec1e8-e26f-4b1c-a378-2d3d4aa797f6 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/python/s/dictionary-to-list.md | unknown | 4085b1cb-9dd0-4edd-8dec-9ba2c82d946d | 3 | SemanticChunker@1.0.0 | 69af7b646ba7e1d9ff022a0312bc507a34283ee03394ca9ba6a44e6a579f4bfc | [Dictionary to list > Map list to dictionary]
## Map list to dictionary
If you want to map the values of a list to a dictionary using a function, where the key-value pairs consist of the original value as the key and the result of the function as the value, you can use a similar technique. Instead of simply using `zi... | unknown | unknown | [Dictionary to list > Map list to dictionary]
## Map list to dictionary
If you want to map the values of a list to a dictionary using a function, where the key-value pairs consist of the original value as the key and the result of the function as the value, you can use a similar technique. Instead of simply using `zi... | [Dictionary to list > Map list to dictionary]
## Map list to dictionary
If you want to map the values of a list to a dictionary using a function, where the key-value pairs consist of the original value as the key and the result of the function as the value, you can use a similar technique. Instead of simply using `zi... | code_snippets | ||
6b583962-1ba0-4ce4-8653-0f7dc52d5261 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/python/s/dictionary-to-list.md | unknown | 4085b1cb-9dd0-4edd-8dec-9ba2c82d946d | 1 | SemanticChunker@1.0.0 | 25b331fdff7df12e3ded43d563df2fd4c2ec83b6db86d862f14108c6d75f09cc | [Dictionary to list]
## Dictionary to list
To convert a dictionary to a list of tuples, use `dict.items()` and `list()` to get a list of tuples from the given dictionary.
```py
def dict_to_list(d):
return list(d.items())
d = {'one': 1, 'three': 3, 'five': 5, 'two': 2, 'four': 4}
dict_to_list(d)
# [('one', 1), ('th... | unknown | unknown | [Dictionary to list]
## Dictionary to list
To convert a dictionary to a list of tuples, use `dict.items()` and `list()` to get a list of tuples from the given dictionary.
```py
def dict_to_list(d):
return list(d.items())
d = {'one': 1, 'three': 3, 'five': 5, 'two': 2, 'four': 4}
dict_to_list(d)
# [('one', 1), ('th... | [Dictionary to list]
## Dictionary to list
To convert a dictionary to a list of tuples, use `dict.items()` and `list()` to get a list of tuples from the given dictionary.
```py
def dict_to_list(d):
return list(d.items())
d = {'one': 1, 'three': 3, 'five': 5, 'two': 2, 'four': 4}
dict_to_list(d)
# [('one', 1), ('th... | code_snippets | ||
c481a742-c6ca-4caa-95fe-23cdb38f792d | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/python/s/dictionary-to-list.md | unknown | 4085b1cb-9dd0-4edd-8dec-9ba2c82d946d | 2 | SemanticChunker@1.0.0 | 9049b40496f6b663e3383cce0468cca4208a2308306cd948e3c89cfb38fac2f0 | [Dictionary to list > List to dictionary]
## List to dictionary
In order to combine two lists into a dictionary, the elements of the first one will serve as the keys and the elements of the second one serve as the values.
The values of the first list need to be unique and hashable.
Given these preconditions, use `zi... | unknown | unknown | [Dictionary to list > List to dictionary]
## List to dictionary
In order to combine two lists into a dictionary, the elements of the first one will serve as the keys and the elements of the second one serve as the values.
The values of the first list need to be unique and hashable.
Given these preconditions, use `zi... | [Dictionary to list > List to dictionary]
## List to dictionary
In order to combine two lists into a dictionary, the elements of the first one will serve as the keys and the elements of the second one serve as the values.
The values of the first list need to be unique and hashable.
Given these preconditions, use `zi... | code_snippets | ||
8c4cc1ba-184e-4194-9a5e-45aeafdb14e8 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/python/s/file-close.md | unknown | cf426dce-4696-496e-8342-a6c34482ff72 | 0 | SemanticChunker@1.0.0 | b661910c98cbc298167bf548226c856dbd4b43374a40d5e2590ed3500b713bff | ---
title: How to correctly close files in Python
shortTitle: Closing files
language: python
tags: [file]
cover: flower-pond
excerpt: When working with files in Python, it's important to ensure that the file is closed correctly. Here are a couple of ways to do that.
listed: false
dateModified: 2022-02-03
---
When work... | unknown | unknown | ---
title: How to correctly close files in Python
shortTitle: Closing files
language: python
tags: [file]
cover: flower-pond
excerpt: When working with files in Python, it's important to ensure that the file is closed correctly. Here are a couple of ways to do that.
listed: false
dateModified: 2022-02-03
---
When work... | ---
title: How to correctly close files in Python
shortTitle: Closing files
language: python
tags: [file]
cover: flower-pond
excerpt: When working with files in Python, it's important to ensure that the file is closed correctly. Here are a couple of ways to do that.
listed: false
dateModified: 2022-02-03
---
When work... | code_snippets | ||
b7df2d8d-3aea-417f-bceb-ad2c7d0c6581 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/python/s/collect-dictionary.md | unknown | 74bd3fd7-6042-417d-be41-50e25e3b2aae | 0 | SemanticChunker@1.0.0 | af08a453d0fab6882700242fad059a3aed958af473e2f71a431f5f9f70de017f | ---
title: Invert a dictionary
language: python
tags: [dictionary]
cover: working-bee
excerpt: Invert a dictionary with non-unique hashable values.
listed: false
dateModified: 2024-05-08
---
You can invert a dictionary with non-unique hashable values, using some simple Python code. First, you need to use a `collection... | unknown | unknown | ---
title: Invert a dictionary
language: python
tags: [dictionary]
cover: working-bee
excerpt: Invert a dictionary with non-unique hashable values.
listed: false
dateModified: 2024-05-08
---
You can invert a dictionary with non-unique hashable values, using some simple Python code. First, you need to use a `collection... | ---
title: Invert a dictionary
language: python
tags: [dictionary]
cover: working-bee
excerpt: Invert a dictionary with non-unique hashable values.
listed: false
dateModified: 2024-05-08
---
You can invert a dictionary with non-unique hashable values, using some simple Python code. First, you need to use a `collection... | code_snippets | ||
90d067d3-5af6-41d8-b477-d1c880f41b74 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/python/s/empty-list.md | unknown | 5ebb30db-fc9d-4fcb-9f4c-f9bc16bcad37 | 0 | SemanticChunker@1.0.0 | baca5a7d29084c61e14a23b635d56ff8be72cbe45622a2610fa19e5347aa3daa | ---
title: How can I check if a Python list is empty?
shortTitle: Empty list
language: python
tags: [list]
cover: salad-2
excerpt: There's a good way to test the emptiness of a Python list and a better one. Which one are you using?
listed: false
dateModified: 2023-01-15
---
Checking the emptiness of a Python list is r... | unknown | unknown | ---
title: How can I check if a Python list is empty?
shortTitle: Empty list
language: python
tags: [list]
cover: salad-2
excerpt: There's a good way to test the emptiness of a Python list and a better one. Which one are you using?
listed: false
dateModified: 2023-01-15
---
Checking the emptiness of a Python list is r... | ---
title: How can I check if a Python list is empty?
shortTitle: Empty list
language: python
tags: [list]
cover: salad-2
excerpt: There's a good way to test the emptiness of a Python list and a better one. Which one are you using?
listed: false
dateModified: 2023-01-15
---
Checking the emptiness of a Python list is r... | code_snippets | ||
f494d441-cf8a-4263-819a-8f1127e9d3ee | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/python/s/date-difference.md | unknown | e59ac798-cf2f-486f-9fc8-90f25b6330e2 | 0 | SemanticChunker@1.0.0 | b40aec0dacea2ff7f55c0b81c8e05db3372115a2384f2f271db3c8c722da0088 | ---
title: Calculate date difference
shortTitle: Date difference
language: python
tags: [date]
cover: succulent-9
excerpt: Calculates the day, month, or year difference between two dates.
listed: false
dateModified: 2024-07-16
---
Calculating the date difference between two dates in Python is a simple as subtracting o... | unknown | unknown | ---
title: Calculate date difference
shortTitle: Date difference
language: python
tags: [date]
cover: succulent-9
excerpt: Calculates the day, month, or year difference between two dates.
listed: false
dateModified: 2024-07-16
---
Calculating the date difference between two dates in Python is a simple as subtracting o... | ---
title: Calculate date difference
shortTitle: Date difference
language: python
tags: [date]
cover: succulent-9
excerpt: Calculates the day, month, or year difference between two dates.
listed: false
dateModified: 2024-07-16
---
Calculating the date difference between two dates in Python is a simple as subtracting o... | code_snippets | ||
3f939a9d-68f0-410b-896a-0addeceae3a7 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/python/s/code-anatomy-performant-python.md | unknown | 0388dfa2-6422-471c-b516-527059973910 | 0 | SemanticChunker@1.0.0 | 86fcc62fb1eeb2fe38b525218793867470e2111608bcb07ce3afa37d495a5f6a | ---
title: Code Anatomy - Writing high performance Python code
shortTitle: Performant Python code
language: python
tags: [list,performance]
cover: walking-on-top
excerpt: Writing efficient Python code can be tricky. Read how we optimize our list snippets to increase performance using a couple of simple tricks.
listed: ... | unknown | unknown | ---
title: Code Anatomy - Writing high performance Python code
shortTitle: Performant Python code
language: python
tags: [list,performance]
cover: walking-on-top
excerpt: Writing efficient Python code can be tricky. Read how we optimize our list snippets to increase performance using a couple of simple tricks.
listed: ... | ---
title: Code Anatomy - Writing high performance Python code
shortTitle: Performant Python code
language: python
tags: [list,performance]
cover: walking-on-top
excerpt: Writing efficient Python code can be tricky. Read how we optimize our list snippets to increase performance using a couple of simple tricks.
listed: ... | code_snippets | ||
d3f87d90-9386-45f2-ad07-9d848eac3074 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/python/s/code-anatomy-performant-python.md | unknown | 0388dfa2-6422-471c-b516-527059973910 | 1 | SemanticChunker@1.0.0 | 3c0f6561965f74367f20efac99ff16ddd9103075264a2c540894851443aff77c | The solution to this issue is to call `set()` once before the list comprehension and store the result to speed up the process:
```py
def difference(a, b):
_b = set(b)
return [item for item in a if item not in _b]
```
Another option worth mentioning in terms of performance is the use of a list comprehension versus `... | unknown | unknown | The solution to this issue is to call `set()` once before the list comprehension and store the result to speed up the process:
```py
def difference(a, b):
_b = set(b)
return [item for item in a if item not in _b]
```
Another option worth mentioning in terms of performance is the use of a list comprehension versus `... | The solution to this issue is to call `set()` once before the list comprehension and store the result to speed up the process:
```py
def difference(a, b):
_b = set(b)
return [item for item in a if item not in _b]
```
Another option worth mentioning in terms of performance is the use of a list comprehension versus `... | code_snippets | ||
644f3f6c-9ff4-4b57-a3bd-84ff03184fb1 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/python/s/days-ago-days-from-now-add-subtract-dates.md | unknown | 50c6a6ce-5bb6-4d01-99a3-49a94565598b | 3 | SemanticChunker@1.0.0 | db0266a24af74796eee6666170051701dc4acfe39cc2c6253c8c1c20179c2266 | [Days ago > Add days]
## Add days
In order to calculate the date of `n` days from the given date, you can use `datetime.timedelta` and the `+` operator to calculate the new `datetime.datetime` value after adding `n` days to `d`.
```py
from datetime import date, datetime, timedelta
def add_days(n, d = datetime.today... | unknown | unknown | [Days ago > Add days]
## Add days
In order to calculate the date of `n` days from the given date, you can use `datetime.timedelta` and the `+` operator to calculate the new `datetime.datetime` value after adding `n` days to `d`.
```py
from datetime import date, datetime, timedelta
def add_days(n, d = datetime.today... | [Days ago > Add days]
## Add days
In order to calculate the date of `n` days from the given date, you can use `datetime.timedelta` and the `+` operator to calculate the new `datetime.datetime` value after adding `n` days to `d`.
```py
from datetime import date, datetime, timedelta
def add_days(n, d = datetime.today... | code_snippets | ||
683184b0-3b84-41b9-9cea-2d93dd1ad59c | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/python/s/days-ago-days-from-now-add-subtract-dates.md | unknown | 50c6a6ce-5bb6-4d01-99a3-49a94565598b | 1 | SemanticChunker@1.0.0 | 9138924cc75209b173f37f8c53775aa00e99bd17e91eda7b2182ff647a2b5e2a | [Days ago]
## Days ago
To calculate the date of `n` days ago from today, simply use `datetime.date.today()` to get the current day and `datetime.timedelta` to subtract `n` days from it.
```py
from datetime import timedelta, date
def days_ago(n):
return date.today() - timedelta(n)
days_ago(5) # date(2020, 10, 23)
... | unknown | unknown | [Days ago]
## Days ago
To calculate the date of `n` days ago from today, simply use `datetime.date.today()` to get the current day and `datetime.timedelta` to subtract `n` days from it.
```py
from datetime import timedelta, date
def days_ago(n):
return date.today() - timedelta(n)
days_ago(5) # date(2020, 10, 23)
... | [Days ago]
## Days ago
To calculate the date of `n` days ago from today, simply use `datetime.date.today()` to get the current day and `datetime.timedelta` to subtract `n` days from it.
```py
from datetime import timedelta, date
def days_ago(n):
return date.today() - timedelta(n)
days_ago(5) # date(2020, 10, 23)
... | code_snippets | ||
8472afe9-4dce-4faa-9380-85d86569ae16 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/python/s/days-ago-days-from-now-add-subtract-dates.md | unknown | 50c6a6ce-5bb6-4d01-99a3-49a94565598b | 2 | SemanticChunker@1.0.0 | 0f369a4b86275b1be5c3f32d454143abf2ed1f8d7b4a145a18d1af9c44e0d743 | [Days ago > Days from now]
## Days from now
Similarly, to calculate the date of `n` days from today, use `datetime.date.today()` to get the current day and `datetime.timedelta` to add `n` days to it.
```py
from datetime import timedelta, date
def days_from_now(n):
return date.today() + timedelta(n)
days_from_now(... | unknown | unknown | [Days ago > Days from now]
## Days from now
Similarly, to calculate the date of `n` days from today, use `datetime.date.today()` to get the current day and `datetime.timedelta` to add `n` days to it.
```py
from datetime import timedelta, date
def days_from_now(n):
return date.today() + timedelta(n)
days_from_now(... | [Days ago > Days from now]
## Days from now
Similarly, to calculate the date of `n` days from today, use `datetime.date.today()` to get the current day and `datetime.timedelta` to add `n` days to it.
```py
from datetime import timedelta, date
def days_from_now(n):
return date.today() + timedelta(n)
days_from_now(... | code_snippets | ||
8e261066-4c5f-4521-82a6-85b02719a439 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/python/s/days-ago-days-from-now-add-subtract-dates.md | unknown | 50c6a6ce-5bb6-4d01-99a3-49a94565598b | 4 | SemanticChunker@1.0.0 | 1cb1be3f584636fbdc8bf2075cb9bf2699b48b6d8984709c335d589daed64251 | [Days ago > Subtract days]
## Subtract days
Finally, to calculate the date of `n` days before the given date, you can use `datetime.timedelta` and the `-` operator to calculate the new `datetime.datetime` value after subtracting `n` days from `d`.
```py
from datetime import date, datetime, timedelta
def subtract_da... | unknown | unknown | [Days ago > Subtract days]
## Subtract days
Finally, to calculate the date of `n` days before the given date, you can use `datetime.timedelta` and the `-` operator to calculate the new `datetime.datetime` value after subtracting `n` days from `d`.
```py
from datetime import date, datetime, timedelta
def subtract_da... | [Days ago > Subtract days]
## Subtract days
Finally, to calculate the date of `n` days before the given date, you can use `datetime.timedelta` and the `-` operator to calculate the new `datetime.datetime` value after subtracting `n` days from `d`.
```py
from datetime import date, datetime, timedelta
def subtract_da... | code_snippets | ||
e77e25ce-4cf5-4c7b-9894-8e32433097b5 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/python/s/days-ago-days-from-now-add-subtract-dates.md | unknown | 50c6a6ce-5bb6-4d01-99a3-49a94565598b | 0 | SemanticChunker@1.0.0 | 4ccb9bf3355920fff7859bed5b1663d703a990224ca98f515398e2440a74ff02 | ---
title: Days ago, days from now, add and subtract dates
shortTitle: Days ago, days from now
language: python
tags: [date]
cover: cup-of-orange
excerpt: Calculate dates relative to today or a given date by adding or subtracting days.
listed: false
dateModified: 2024-05-19
--- | unknown | unknown | ---
title: Days ago, days from now, add and subtract dates
shortTitle: Days ago, days from now
language: python
tags: [date]
cover: cup-of-orange
excerpt: Calculate dates relative to today or a given date by adding or subtracting days.
listed: false
dateModified: 2024-05-19
--- | ---
title: Days ago, days from now, add and subtract dates
shortTitle: Days ago, days from now
language: python
tags: [date]
cover: cup-of-orange
excerpt: Calculate dates relative to today or a given date by adding or subtracting days.
listed: false
dateModified: 2024-05-19
--- | code_snippets | ||
32f2a132-9631-440b-a7f0-932657609ce6 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/python/s/chunk-list.md | unknown | 5d1f971f-2ddb-431e-b4ce-7131c3b3b73c | 2 | SemanticChunker@1.0.0 | f29fa45d9e65775a98997820501f879e4dfb0573281f24962d5c372dd1ff1811 | [Split a Python list into `n` chunks > Split a Python list into chunks of a specified size]
## Split a Python list into chunks of a specified size
Similarly, you can chunk a list into smaller lists of a specified size. You can use the same approach as above, but instead of calculating the size of each chunk, you can ... | unknown | unknown | [Split a Python list into `n` chunks > Split a Python list into chunks of a specified size]
## Split a Python list into chunks of a specified size
Similarly, you can chunk a list into smaller lists of a specified size. You can use the same approach as above, but instead of calculating the size of each chunk, you can ... | [Split a Python list into `n` chunks > Split a Python list into chunks of a specified size]
## Split a Python list into chunks of a specified size
Similarly, you can chunk a list into smaller lists of a specified size. You can use the same approach as above, but instead of calculating the size of each chunk, you can ... | code_snippets | ||
7018d40c-87c2-49f4-b448-fe3adeb5a489 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/python/s/chunk-list.md | unknown | 5d1f971f-2ddb-431e-b4ce-7131c3b3b73c | 1 | SemanticChunker@1.0.0 | f5151dab3cb0c0de2b4ead29e2d8dc9ab9e69c793736d30d7def0bcc22ca294b | [Split a Python list into `n` chunks]
## Split a Python list into `n` chunks
In order to chunk a list into `n` smaller lists, you first need to calculate the size of each chunk, using `math.ceil()` and `len()`. Then, you can create a new list of size `n` using `list()` and `range()`.
Finally, you can use `map()` to ... | unknown | unknown | [Split a Python list into `n` chunks]
## Split a Python list into `n` chunks
In order to chunk a list into `n` smaller lists, you first need to calculate the size of each chunk, using `math.ceil()` and `len()`. Then, you can create a new list of size `n` using `list()` and `range()`.
Finally, you can use `map()` to ... | [Split a Python list into `n` chunks]
## Split a Python list into `n` chunks
In order to chunk a list into `n` smaller lists, you first need to calculate the size of each chunk, using `math.ceil()` and `len()`. Then, you can create a new list of size `n` using `list()` and `range()`.
Finally, you can use `map()` to ... | code_snippets | ||
e9b92c7c-f98c-43e5-8704-f0be6a1c34a4 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/python/s/chunk-list.md | unknown | 5d1f971f-2ddb-431e-b4ce-7131c3b3b73c | 0 | SemanticChunker@1.0.0 | 6c1578a0bd3eeae33bd53e769977281d5e463bd4101291bfe6d6f24bb1327910 | ---
title: Split a Python list into chunks
shortTitle: Split list into chunks
language: python
tags: [list]
cover: succulent-10
excerpt: Chunks a list into a set amount of smaller lists or into lists of a specified size.
listed: false
dateModified: 2024-07-17
--- | unknown | unknown | ---
title: Split a Python list into chunks
shortTitle: Split list into chunks
language: python
tags: [list]
cover: succulent-10
excerpt: Chunks a list into a set amount of smaller lists or into lists of a specified size.
listed: false
dateModified: 2024-07-17
--- | ---
title: Split a Python list into chunks
shortTitle: Split list into chunks
language: python
tags: [list]
cover: succulent-10
excerpt: Chunks a list into a set amount of smaller lists or into lists of a specified size.
listed: false
dateModified: 2024-07-17
--- | code_snippets | ||
c5a1b821-95a9-4ca8-9e8c-9a3cda3f3fd8 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/python/s/byte-size.md | unknown | 578421fb-f310-4ce3-ac3e-fc80a5a70839 | 0 | SemanticChunker@1.0.0 | bd03a438f881931ecb1f2fac19a309dfe6b9971d5985e33a768faf96912902d6 | ---
title: Byte size of a Python string
shortTitle: Byte size
language: python
tags: [string]
cover: river-house-lights
excerpt: Find the byte size of a Python string, containing special characters or not.
listed: false
dateModified: 2024-08-16
---
The byte size of a string is the number of bytes required to encode it... | unknown | unknown | ---
title: Byte size of a Python string
shortTitle: Byte size
language: python
tags: [string]
cover: river-house-lights
excerpt: Find the byte size of a Python string, containing special characters or not.
listed: false
dateModified: 2024-08-16
---
The byte size of a string is the number of bytes required to encode it... | ---
title: Byte size of a Python string
shortTitle: Byte size
language: python
tags: [string]
cover: river-house-lights
excerpt: Find the byte size of a Python string, containing special characters or not.
listed: false
dateModified: 2024-08-16
---
The byte size of a string is the number of bytes required to encode it... | code_snippets | ||
5a5ada9b-3273-42f9-a713-6db070c9ce82 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/python/s/identity-equality.md | unknown | c7c8473c-c114-4ee9-b62a-1e74040914be | 0 | SemanticChunker@1.0.0 | 4bfe673a0c5a883f3062e35ddbcb49aeea8eb97ab73a6e76eec2560e32f88b18 | ---
title: What is the difference between Python's equality operators?
shortTitle: Python equality operators
language: python
tags: [type,comparison]
cover: umbrellas
excerpt: Python provides two distinct comparison operators for different task. Stop mixing them up using this quick guide.
listed: false
dateModified: 20... | unknown | unknown | ---
title: What is the difference between Python's equality operators?
shortTitle: Python equality operators
language: python
tags: [type,comparison]
cover: umbrellas
excerpt: Python provides two distinct comparison operators for different task. Stop mixing them up using this quick guide.
listed: false
dateModified: 20... | ---
title: What is the difference between Python's equality operators?
shortTitle: Python equality operators
language: python
tags: [type,comparison]
cover: umbrellas
excerpt: Python provides two distinct comparison operators for different task. Stop mixing them up using this quick guide.
listed: false
dateModified: 20... | code_snippets | ||
5321e88f-ae55-478a-8640-542469935d85 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/python/s/is-weekend-or-weekday.md | unknown | cfa8ac8e-9c0e-4e9d-8253-516aad536fb7 | 1 | SemanticChunker@1.0.0 | c4034db300257642839977fbc04da0323bad9a6f28c9f94707d829388a3a1835 | [Date is weekend > Date is weekday]
## Date is weekday
For the opposite case (checking if the date is a weekday), you can use the same technique, but checking if the day of the week is less than or equal to `4`.
```py
from datetime import datetime, date
def is_weekday(d = datetime.today()):
return d.weekday() <= 4... | unknown | unknown | [Date is weekend > Date is weekday]
## Date is weekday
For the opposite case (checking if the date is a weekday), you can use the same technique, but checking if the day of the week is less than or equal to `4`.
```py
from datetime import datetime, date
def is_weekday(d = datetime.today()):
return d.weekday() <= 4... | [Date is weekend > Date is weekday]
## Date is weekday
For the opposite case (checking if the date is a weekday), you can use the same technique, but checking if the day of the week is less than or equal to `4`.
```py
from datetime import datetime, date
def is_weekday(d = datetime.today()):
return d.weekday() <= 4... | code_snippets | ||
9ff6e726-7adc-4b7c-9226-dd00cf324aa8 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/python/s/is-weekend-or-weekday.md | unknown | cfa8ac8e-9c0e-4e9d-8253-516aad536fb7 | 0 | SemanticChunker@1.0.0 | 5c1efe49b55a2c96c7ce72d33bb73e533278f3e0004ad8a6516bf6b44faa0ade | [Date is weekend]
## Date is weekend
To check if the given date is a weekend, you can use `datetime.datetime.weekday()` to get the day of the week as an integer. Then, you can check if the day of the week is greater than `4`.
```py
from datetime import datetime, date
def is_weekend(d = datetime.today()):
return d.... | unknown | unknown | [Date is weekend]
## Date is weekend
To check if the given date is a weekend, you can use `datetime.datetime.weekday()` to get the day of the week as an integer. Then, you can check if the day of the week is greater than `4`.
```py
from datetime import datetime, date
def is_weekend(d = datetime.today()):
return d.... | [Date is weekend]
## Date is weekend
To check if the given date is a weekend, you can use `datetime.datetime.weekday()` to get the day of the week as an integer. Then, you can check if the day of the week is greater than `4`.
```py
from datetime import datetime, date
def is_weekend(d = datetime.today()):
return d.... | code_snippets | ||
1b9b2594-c7c7-4466-9bbd-259f1d919d96 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/python/s/hex-to-rgb.md | unknown | cc05ceb0-cb84-420f-a95b-5062edf7267b | 2 | SemanticChunker@1.0.0 | 64b0a345468bb5100324453ee3fa42e2484738b748dc40bf023a975f84da301d | [Hex to RGB > RGB to hex]
## RGB to hex
Converting the values of RGB components to a hexadecimal color code is also straightforward. You can create a placeholder for a zero-padded hexadecimal value using `'{:02X}'` and copy it three times. Then, use `str.format()` on the resulting string to replace the placeholders w... | unknown | unknown | [Hex to RGB > RGB to hex]
## RGB to hex
Converting the values of RGB components to a hexadecimal color code is also straightforward. You can create a placeholder for a zero-padded hexadecimal value using `'{:02X}'` and copy it three times. Then, use `str.format()` on the resulting string to replace the placeholders w... | [Hex to RGB > RGB to hex]
## RGB to hex
Converting the values of RGB components to a hexadecimal color code is also straightforward. You can create a placeholder for a zero-padded hexadecimal value using `'{:02X}'` and copy it three times. Then, use `str.format()` on the resulting string to replace the placeholders w... | code_snippets | ||
21043bf3-f726-4b77-9236-0fba1b778cfb | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/python/s/hex-to-rgb.md | unknown | cc05ceb0-cb84-420f-a95b-5062edf7267b | 0 | SemanticChunker@1.0.0 | 9c2d9c2958b5d24f185d564d99f59fe4578b0a5dd1877db8088d86c0b1b00b9c | ---
title: Convert between hex and RGB
language: python
tags: [string,math]
cover: sleepy-cat
excerpt: Converts a hexadecimal color code to a tuple of integers corresponding to its RGB components and vice versa.
listed: false
dateModified: 2024-08-11
--- | unknown | unknown | ---
title: Convert between hex and RGB
language: python
tags: [string,math]
cover: sleepy-cat
excerpt: Converts a hexadecimal color code to a tuple of integers corresponding to its RGB components and vice versa.
listed: false
dateModified: 2024-08-11
--- | ---
title: Convert between hex and RGB
language: python
tags: [string,math]
cover: sleepy-cat
excerpt: Converts a hexadecimal color code to a tuple of integers corresponding to its RGB components and vice versa.
listed: false
dateModified: 2024-08-11
--- | code_snippets | ||
b885e106-ebc2-4b32-ac87-cc99b947faa2 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/python/s/hex-to-rgb.md | unknown | cc05ceb0-cb84-420f-a95b-5062edf7267b | 1 | SemanticChunker@1.0.0 | af37f71f77b8190d38dd4eaa9d0812c75df1894326cd428d4d770b2f8604afc0 | [Hex to RGB]
## Hex to RGB
Converting a hexadecimal color code to a tuple of integers corresponding to its RGB components is fairly simple, All you need to do is use a list comprehension in combination with `int()` and list slice notation to get the RGB components from the hexadecimal string, then use `tuple()` to co... | unknown | unknown | [Hex to RGB]
## Hex to RGB
Converting a hexadecimal color code to a tuple of integers corresponding to its RGB components is fairly simple, All you need to do is use a list comprehension in combination with `int()` and list slice notation to get the RGB components from the hexadecimal string, then use `tuple()` to co... | [Hex to RGB]
## Hex to RGB
Converting a hexadecimal color code to a tuple of integers corresponding to its RGB components is fairly simple, All you need to do is use a list comprehension in combination with `int()` and list slice notation to get the RGB components from the hexadecimal string, then use `tuple()` to co... | code_snippets | ||
2b5cdc31-a3ee-48c8-aea9-9862522825c2 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/python/s/key-of-min-max.md | unknown | 68ddb5c3-9350-4506-a116-3bd8ca18366f | 0 | SemanticChunker@1.0.0 | 5018a0c89c3b336656d07df3a40dc533c62ca9c18b8b7885e92a6482b1c61083 | ---
title: Find the key of the min or max value in a Python dictionary
shortTitle: Key of min or max value in a dictionary
language: python
tags: [dictionary]
cover: goat-wooden-cottage
excerpt: Find the key of the minimum or maximum value in a Python dictionary.
listed: false
dateModified: 2024-05-08
---
Python's `mi... | unknown | unknown | ---
title: Find the key of the min or max value in a Python dictionary
shortTitle: Key of min or max value in a dictionary
language: python
tags: [dictionary]
cover: goat-wooden-cottage
excerpt: Find the key of the minimum or maximum value in a Python dictionary.
listed: false
dateModified: 2024-05-08
---
Python's `mi... | ---
title: Find the key of the min or max value in a Python dictionary
shortTitle: Key of min or max value in a dictionary
language: python
tags: [dictionary]
cover: goat-wooden-cottage
excerpt: Find the key of the minimum or maximum value in a Python dictionary.
listed: false
dateModified: 2024-05-08
---
Python's `mi... | code_snippets | ||
538ebe2c-e2ce-489d-a77b-a6981ccd9bec | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/python/s/key-of-min-max.md | unknown | 68ddb5c3-9350-4506-a116-3bd8ca18366f | 2 | SemanticChunker@1.0.0 | ad37de175e0e9c0380e55c9aaa929566d6c9c839a3a80e9844ca083daab2175f | [Key of the minimum value in a dictionary > Key of the maximum value in a dictionary]
## Key of the maximum value in a dictionary
Subsequently, you can replace `min()` with `max()` to find the key of the maximum value in the dictionary.
```py
def key_of_max(d):
return max(d, key = d.get)
key_of_max({'a':4, 'b':0, ... | unknown | unknown | [Key of the minimum value in a dictionary > Key of the maximum value in a dictionary]
## Key of the maximum value in a dictionary
Subsequently, you can replace `min()` with `max()` to find the key of the maximum value in the dictionary.
```py
def key_of_max(d):
return max(d, key = d.get)
key_of_max({'a':4, 'b':0, ... | [Key of the minimum value in a dictionary > Key of the maximum value in a dictionary]
## Key of the maximum value in a dictionary
Subsequently, you can replace `min()` with `max()` to find the key of the maximum value in the dictionary.
```py
def key_of_max(d):
return max(d, key = d.get)
key_of_max({'a':4, 'b':0, ... | code_snippets | ||
c43dbde7-991e-4bef-bf08-87e85f5a17f9 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/python/s/key-of-min-max.md | unknown | 68ddb5c3-9350-4506-a116-3bd8ca18366f | 1 | SemanticChunker@1.0.0 | de601759e63f6b3cc211bdf400d8d181d15706e41d0fcbc8113554387e48125f | [Key of the minimum value in a dictionary]
## Key of the minimum value in a dictionary
You can use `min()` with the `key` parameter set to `dict.get()` to find and return the key of the minimum value in a given dictionary.
```py
def key_of_min(d):
return min(d, key = d.get)
key_of_min({'a':4, 'b':0, 'c':13}) # b
`... | unknown | unknown | [Key of the minimum value in a dictionary]
## Key of the minimum value in a dictionary
You can use `min()` with the `key` parameter set to `dict.get()` to find and return the key of the minimum value in a given dictionary.
```py
def key_of_min(d):
return min(d, key = d.get)
key_of_min({'a':4, 'b':0, 'c':13}) # b
`... | [Key of the minimum value in a dictionary]
## Key of the minimum value in a dictionary
You can use `min()` with the `key` parameter set to `dict.get()` to find and return the key of the minimum value in a given dictionary.
```py
def key_of_min(d):
return min(d, key = d.get)
key_of_min({'a':4, 'b':0, 'c':13}) # b
`... | code_snippets | ||
da2c7af8-c090-48dc-b54b-2534830dcdb6 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/python/s/fstrings-str-format.md | unknown | a7b05581-dd7b-4655-a7e2-b608ed1bdcf7 | 2 | SemanticChunker@1.0.0 | b78833b7ea6a6d545867a1f020c021128d441231eeae7b180856a45589c68eda | [f-string > str.format()]
## str.format()
The [`str.format()`](https://docs.python.org/3/library/stdtypes.html?highlight=str%20format#str.format) method works very much alike f-strings, the main difference being that replacement fields are supplied as arguments instead of as part of the string.
```py
name = 'John'
a... | unknown | unknown | [f-string > str.format()]
## str.format()
The [`str.format()`](https://docs.python.org/3/library/stdtypes.html?highlight=str%20format#str.format) method works very much alike f-strings, the main difference being that replacement fields are supplied as arguments instead of as part of the string.
```py
name = 'John'
a... | [f-string > str.format()]
## str.format()
The [`str.format()`](https://docs.python.org/3/library/stdtypes.html?highlight=str%20format#str.format) method works very much alike f-strings, the main difference being that replacement fields are supplied as arguments instead of as part of the string.
```py
name = 'John'
a... | code_snippets | ||
ee733113-d018-49dd-8ef6-ee982fb0ac3c | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/python/s/fstrings-str-format.md | unknown | a7b05581-dd7b-4655-a7e2-b608ed1bdcf7 | 0 | SemanticChunker@1.0.0 | 52bd49d8617c8d4118ca698470cf1f29e88b1c62935c9b425d167d6cdf1434ca | ---
title: 2 ways to format a string in Python
shortTitle: String formatting
language: python
tags: [string]
cover: feathers
excerpt: Learn two ways to format a string in Python with this quick tip.
listed: false
dateModified: 2021-06-12
--- | unknown | unknown | ---
title: 2 ways to format a string in Python
shortTitle: String formatting
language: python
tags: [string]
cover: feathers
excerpt: Learn two ways to format a string in Python with this quick tip.
listed: false
dateModified: 2021-06-12
--- | ---
title: 2 ways to format a string in Python
shortTitle: String formatting
language: python
tags: [string]
cover: feathers
excerpt: Learn two ways to format a string in Python with this quick tip.
listed: false
dateModified: 2021-06-12
--- | code_snippets | ||
fd59326e-c76f-4d3d-9aab-dfb5761cc716 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/python/s/fstrings-str-format.md | unknown | a7b05581-dd7b-4655-a7e2-b608ed1bdcf7 | 1 | SemanticChunker@1.0.0 | a54e538aafc9f0f141b24628ba0dcc17c39462c710bf44543253abfcc6853d0f | [f-string]
## f-string
[Formatted string literals](https://docs.python.org/3/reference/lexical_analysis.html?highlight=lexical%20analysis#formatted-string-literals), commonly known as f-strings, are strings prefixed with `'f`' or `'F'`. These strings can contain replacement fields, enclosed in curly braces (`{}`).
`... | unknown | unknown | [f-string]
## f-string
[Formatted string literals](https://docs.python.org/3/reference/lexical_analysis.html?highlight=lexical%20analysis#formatted-string-literals), commonly known as f-strings, are strings prefixed with `'f`' or `'F'`. These strings can contain replacement fields, enclosed in curly braces (`{}`).
`... | [f-string]
## f-string
[Formatted string literals](https://docs.python.org/3/reference/lexical_analysis.html?highlight=lexical%20analysis#formatted-string-literals), commonly known as f-strings, are strings prefixed with `'f`' or `'F'`. These strings can contain replacement fields, enclosed in curly braces (`{}`).
`... | code_snippets | ||
27574ec4-f1f4-4526-81b2-93574d26c5a6 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/python/s/initialize-list-with-range-value-daterange.md | unknown | e685e4f5-cccf-406d-b4f7-02cf2bafe64c | 0 | SemanticChunker@1.0.0 | 8b0a4534fc78b6c1fad5a0b00c36421e9428a78a46536f321bb34a5c5815e3b1 | ---
title: Initialize lists with values, ranges & dates
shortTitle: Initialize list
language: python
tags: [list,date]
cover: succulent-3
excerpt: Master list initialization, using simple techniques and level up your Python skills.
listed: false
dateModified: 2024-05-30
--- | unknown | unknown | ---
title: Initialize lists with values, ranges & dates
shortTitle: Initialize list
language: python
tags: [list,date]
cover: succulent-3
excerpt: Master list initialization, using simple techniques and level up your Python skills.
listed: false
dateModified: 2024-05-30
--- | ---
title: Initialize lists with values, ranges & dates
shortTitle: Initialize list
language: python
tags: [list,date]
cover: succulent-3
excerpt: Master list initialization, using simple techniques and level up your Python skills.
listed: false
dateModified: 2024-05-30
--- | code_snippets | ||
851a5918-9d5c-4325-ac7f-29eee3d6dc65 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/python/s/initialize-list-with-range-value-daterange.md | unknown | e685e4f5-cccf-406d-b4f7-02cf2bafe64c | 2 | SemanticChunker@1.0.0 | 2283dede37ab6f94e700ee684e7739fad1e46694abe718784a8d16b296fd3401 | [Initialize list with values > Initialize list with numeric range]
## Initialize list with numeric range
For a numeric range between `start` and `end` (inclusive), you can use a list comprehension and `range()` to generate a list of the appropriate length, filled with the desired values in the given range.
```py
def... | unknown | unknown | [Initialize list with values > Initialize list with numeric range]
## Initialize list with numeric range
For a numeric range between `start` and `end` (inclusive), you can use a list comprehension and `range()` to generate a list of the appropriate length, filled with the desired values in the given range.
```py
def... | [Initialize list with values > Initialize list with numeric range]
## Initialize list with numeric range
For a numeric range between `start` and `end` (inclusive), you can use a list comprehension and `range()` to generate a list of the appropriate length, filled with the desired values in the given range.
```py
def... | code_snippets | ||
adefc865-fe36-4c53-aee4-64021a0106ed | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/python/s/initialize-list-with-range-value-daterange.md | unknown | e685e4f5-cccf-406d-b4f7-02cf2bafe64c | 1 | SemanticChunker@1.0.0 | 848ff660f2fa386fbe42dbba9f557c88397beb3477f065a144bd8305aa3b1bbd | [Initialize list with values]
## Initialize list with values
In order to initialize a list with a specific value, all you need to do is to use a list comprehension and `range()` to generate a list of length equal to `n`, filled with the desired values.
```py
def initialize_list_with_values(n, val = 0):
return [val ... | unknown | unknown | [Initialize list with values]
## Initialize list with values
In order to initialize a list with a specific value, all you need to do is to use a list comprehension and `range()` to generate a list of length equal to `n`, filled with the desired values.
```py
def initialize_list_with_values(n, val = 0):
return [val ... | [Initialize list with values]
## Initialize list with values
In order to initialize a list with a specific value, all you need to do is to use a list comprehension and `range()` to generate a list of length equal to `n`, filled with the desired values.
```py
def initialize_list_with_values(n, val = 0):
return [val ... | code_snippets | ||
ccfa8c7b-6601-4330-a1bd-cddb981d02c7 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/python/s/initialize-list-with-range-value-daterange.md | unknown | e685e4f5-cccf-406d-b4f7-02cf2bafe64c | 3 | SemanticChunker@1.0.0 | 7cfe686b68ded8876ea830f17181bea1fc12bb78261ccfebe4bf2356ccab1768 | [Initialize list with values > Initialize list with date range]
## Initialize list with date range
Similarly, for a list with dates between `start` (inclusive) and `end` (not inclusive), you can use a list comprehension and `datetime.timedelta` to generate a list of `datetime.date` objects.
```py
from datetime impor... | unknown | unknown | [Initialize list with values > Initialize list with date range]
## Initialize list with date range
Similarly, for a list with dates between `start` (inclusive) and `end` (not inclusive), you can use a list comprehension and `datetime.timedelta` to generate a list of `datetime.date` objects.
```py
from datetime impor... | [Initialize list with values > Initialize list with date range]
## Initialize list with date range
Similarly, for a list with dates between `start` (inclusive) and `end` (not inclusive), you can use a list comprehension and `datetime.timedelta` to generate a list of `datetime.date` objects.
```py
from datetime impor... | code_snippets | ||
dae84d24-a28c-4521-94aa-599ced049d47 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/python/s/initialize-list-with-range-value-daterange.md | unknown | e685e4f5-cccf-406d-b4f7-02cf2bafe64c | 4 | SemanticChunker@1.0.0 | 68b0deba709895fdc55751cd4a19d070d3e0b1444f85083832811a21b47eb028 | [Initialize list with values > Initialize 2D list]
## Initialize 2D list
Finally, for a 2D list, you'll need to use a nested list comprehension to generate a list of lists, where each inner list is initialized with the desired value.
```py
def initialize_2d_list(w, h, val = None):
return [[val for x in range(w)] fo... | unknown | unknown | [Initialize list with values > Initialize 2D list]
## Initialize 2D list
Finally, for a 2D list, you'll need to use a nested list comprehension to generate a list of lists, where each inner list is initialized with the desired value.
```py
def initialize_2d_list(w, h, val = None):
return [[val for x in range(w)] fo... | [Initialize list with values > Initialize 2D list]
## Initialize 2D list
Finally, for a 2D list, you'll need to use a nested list comprehension to generate a list of lists, where each inner list is initialized with the desired value.
```py
def initialize_2d_list(w, h, val = None):
return [[val for x in range(w)] fo... | code_snippets | ||
c6a82479-7aed-4035-9f0d-115d356ab892 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/python/s/hamming-distance.md | unknown | 5dfbaa4f-21a1-45d0-bc51-c3d3aedcf615 | 0 | SemanticChunker@1.0.0 | 6d6077ce14deb0482f9d87ba5ea95090dc808af078b4fd5c438cf9e0d94d4e7c | ---
title: Hamming distance
language: python
tags: [math]
cover: tulips-and-reeds
excerpt: Learn how to calculate the Hamming distance between two values.
listed: false
dateModified: 2024-05-11
---
The Hamming distance between two integers is the number of positions at which the corresponding bits are different.
To c... | unknown | unknown | ---
title: Hamming distance
language: python
tags: [math]
cover: tulips-and-reeds
excerpt: Learn how to calculate the Hamming distance between two values.
listed: false
dateModified: 2024-05-11
---
The Hamming distance between two integers is the number of positions at which the corresponding bits are different.
To c... | ---
title: Hamming distance
language: python
tags: [math]
cover: tulips-and-reeds
excerpt: Learn how to calculate the Hamming distance between two values.
listed: false
dateModified: 2024-05-11
---
The Hamming distance between two integers is the number of positions at which the corresponding bits are different.
To c... | code_snippets |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.