summaryrefslogtreecommitdiffstatshomepage
path: root/py/objlist.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-01-05 23:58:49 +0000
committerDamien George <damien.p.george@gmail.com>2014-01-05 23:58:49 +0000
commit8137b004b004d8e3a594eab90afccb72b779273a (patch)
tree194364c2d286c23a17182bca062261817be91d96 /py/objlist.c
parentaa35fc60d77085781ab862fa9a048d3c35823d83 (diff)
parentd52a0318ce266e1d9ce0d877f64a8fe097cef080 (diff)
downloadmicropython-8137b004b004d8e3a594eab90afccb72b779273a.tar.gz
micropython-8137b004b004d8e3a594eab90afccb72b779273a.zip
Merge branch 'list_remove' of git://github.com/chipaca/micropython into chipaca-list_remove
Diffstat (limited to 'py/objlist.c')
-rw-r--r--py/objlist.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/py/objlist.c b/py/objlist.c
index df03d9ae17..dc7ff3e176 100644
--- a/py/objlist.c
+++ b/py/objlist.c
@@ -226,6 +226,15 @@ static mp_obj_t list_insert(mp_obj_t self_in, mp_obj_t idx, mp_obj_t obj) {
return mp_const_none;
}
+static mp_obj_t list_remove(mp_obj_t self_in, mp_obj_t value) {
+ assert(MP_OBJ_IS_TYPE(self_in, &list_type));
+ mp_obj_t args[] = {self_in, value};
+ args[1] = list_index(2, args);
+ list_pop(2, args);
+
+ return mp_const_none;
+}
+
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);
@@ -233,6 +242,7 @@ static MP_DEFINE_CONST_FUN_OBJ_2(list_count_obj, list_count);
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(list_index_obj, 2, 4, list_index);
static MP_DEFINE_CONST_FUN_OBJ_3(list_insert_obj, list_insert);
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(list_pop_obj, 1, 2, list_pop);
+static MP_DEFINE_CONST_FUN_OBJ_2(list_remove_obj, list_remove);
static MP_DEFINE_CONST_FUN_OBJ_2(list_sort_obj, list_sort);
const mp_obj_type_t list_type = {
@@ -251,6 +261,7 @@ const mp_obj_type_t list_type = {
{ "index", &list_index_obj },
{ "insert", &list_insert_obj },
{ "pop", &list_pop_obj },
+ { "remove", &list_remove_obj },
{ "sort", &list_sort_obj },
{ NULL, NULL }, // end-of-list sentinel
},