Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Traverse all paths of a two-dimensional matrix

2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

#! / usr/bin/env python

#-*-coding: utf-8-*-

Def printList (datalist = []):

For i in range (len (datalist)):

Print datalist [i]

Def mergeList (list1, list2 = []):

If len (list1) = = 0:

Return list2

If len (list2) = = 0:

Return list1

List3 = []

For list1_i in range (len (list1)):

For list2_i in range (len (list2)):

List3_item = str (List1 [List1 _ I]) +'-'+ str (List2 [List2 _ I])

List3.append (list3_item)

Return list3

Def row2columnList (datalist = []):

List_cr = [[]]

For col in range (len (datalist [0])):

List_tmp = []

For row in range (len (datalist)):

List_tmp.append (datalist [row] [col])

List_cr.append (list_tmp)

Return list_cr

Def traversalPath (datalist = []):

List_tmp = []

For row in range (len (datalist)):

List_tmp = mergeList (list_tmp, datalist [row])

Return list_tmp

If _ _ name__=='__main__':

M = [['a _ 1,'b _ 1,'c _ 1,'d _ 1,'e _ 1], ['a _ 2,'b _ 2, c _ 2, d _ 2, e _ 2], [a _ 3, b _ 3, c _ 3, d _ 3, e _ 3]]

M_tmp = row2columnList (M)

Tp_list = traversalPath (M_tmp)

PrintList (tp_list)

Print len (tp_list)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report