键盘快捷键

使用 跳转章节

使用 S/ 在本书内搜索

使用 ? 显示帮助页面

使用 Esc 隐藏帮助页面

Zip

Zip[list1, list2]

Combines two lists into a single list of pairs. The resulting list has the same length as the shorter input list; extra elements from the longer list are ignored.

  • Returns a List of two‑element Lists.
Zip[{ 1, 2, 3 }, { "a", "b" }];  (* => {{1, "a"}, {2, "b"}} *)
Zip[{ 1 }, { 2, 3, 4 }];         (* => {{1, 2}} *)

ZipWith

ZipWith[list1, list2, fun]

Combines corresponding elements from list1 and list2 by applying the binary function fun. The resulting list has the same length as the shorter input list.

  • fun must accept two arguments.
  • Returns a List containing the results.
ZipWith[{ 1, 2, 3 }, { 4, 5, 6 }, Add];       (* => {5, 7, 9} *)
ZipWith[{ "a", "b" }, { "c", "d" }, Concat];  (* => {"ac", "bd"} *)