| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| from lpython import i32, f64 | ||
|
|
||
|
|
||
| def test_builtin_reversed(): | ||
| # list of strings | ||
| alphabets: list[str] = ["a", "b", "c", "d", "e"] | ||
|
|
||
| reversed_alphabets: list[str] = reversed(alphabets) | ||
| print(reversed_alphabets) | ||
| assert reversed_alphabets == ["e", "d", "c", "b", "a"] | ||
|
|
||
| # list of numbers | ||
| numbers: list[i32] = [1, 2, 3, 4, 5] | ||
|
|
||
| reversed_numbers: list[i32] = reversed(numbers) | ||
| print(reversed_numbers) | ||
| assert reversed_numbers == [5, 4, 3, 2, 1] | ||
|
|
||
| # list returned through function call | ||
| alphabet_dictionary: dict[str, i32] = { | ||
| "a": 1, | ||
| "b": 2, | ||
| "c": 3, | ||
| "d": 4, | ||
| "e": 5, | ||
| } | ||
| reversed_keys: list[str] = reversed(alphabet_dictionary.keys()) | ||
| print(reversed_keys) | ||
|
|
||
| assert reversed_keys == ["e", "d", "c", "b", "a"] | ||
|
|
||
| # list of another object | ||
| points: list[tuple[f64, f64]] = [(1.0, 0.0), (2.3, 5.9), (78.1, 23.2)] | ||
| reversed_points: list[tuple[f64, f64]] = reversed(points) | ||
| print(reversed_points) | ||
|
|
||
| assert reversed_points == [(78.1, 23.2), (2.3, 5.9), (1.0, 0.0)] | ||
|
|
||
|
|
||
| test_builtin_reversed() |
| Back | FazBrowse Home | New Git URL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityReversed returns an iterator, but does not actually reverse a list. I think we do not have support for iterators yet in LPython.
The approach in this PR reverses the entire list, which I think is not the correct approach.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality@Shaikh-Ubaid I return a reversed list using the approach used for dict.keys (#1881 (comment)) as we do not support iterators now.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.