Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
26c21164
Commit
26c21164
authored
Jan 03, 2014
by
John R. Lenton
Browse files
Implemented list.copy. Fixes issue #54.
parent
069ded95
Changes
2
Hide whitespace changes
Inline
Side-by-side
py/objlist.c
View file @
26c21164
...
...
@@ -134,8 +134,15 @@ static mp_obj_t list_clear(mp_obj_t self_in) {
return
mp_const_none
;
}
static
mp_obj_t
list_copy
(
mp_obj_t
self_in
)
{
assert
(
MP_OBJ_IS_TYPE
(
self_in
,
&
list_type
));
mp_obj_list_t
*
self
=
self_in
;
return
mp_obj_new_list
(
self
->
len
,
self
->
items
);
}
static
MP_DEFINE_CONST_FUN_OBJ_2
(
list_append_obj
,
mp_obj_list_append
);
static
MP_DEFINE_CONST_FUN_OBJ_1
(
list_clear_obj
,
list_clear
);
static
MP_DEFINE_CONST_FUN_OBJ_1
(
list_copy_obj
,
list_copy
);
static
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN
(
list_pop_obj
,
1
,
2
,
list_pop
);
static
MP_DEFINE_CONST_FUN_OBJ_2
(
list_sort_obj
,
list_sort
);
...
...
@@ -151,6 +158,7 @@ const mp_obj_type_t list_type = {
{
// method list
{
"append"
,
&
list_append_obj
},
{
"clear"
,
&
list_clear_obj
},
{
"copy"
,
&
list_copy_obj
},
{
"pop"
,
&
list_pop_obj
},
{
"sort"
,
&
list_sort_obj
},
{
NULL
,
NULL
},
// end-of-list sentinel
...
...
tests/basics/tests/list_copy.py
0 → 100644
View file @
26c21164
# list copy tests
a
=
[
1
,
2
,
[]]
b
=
a
.
copy
()
a
[
-
1
].
append
(
1
)
a
.
append
(
4
)
print
(
a
)
print
(
b
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment