当前位置:网站首页>Double for loop
Double for loop
2022-07-29 02:50:00 【qq_ forty-two million three hundred and seven thousand five hun】
for r in range(4):
for c in range(6):
if c % 2 == 0:
print("*", end="")
else:
print("#", end="")
print()
Outer loop control inner row control column
“”"
0
01
012
0123
“”"
Row fixed as 4 The rows and columns should change with the rows
for r in range(4):
for c in range(r+1):
print(c,end="")
print()
for r in range(4):
for c in range(r+1):
print("*",end="")
print()
Sort the list ( Ascending small –> Big )
""" Comparing the two thought Take the first one and compare it with the second Take out the second one and compare it with the three If the extracted element is larger than the second, the position is exchanged .... """
list01 = [3, 80, 45, 5, 7, 1]
for r in range(len(list01)-1):
for c in range(r + 1, len(list01)):
if list01[r] > list01[c]:
list01[r], list01[c] = list01[c], list01[r]
print(list01)
""" Judge that the list elements have the same [3,80,45,5,80,1] Ideas : Compare all elements in pairs , If the same one is found, the result will be printed All element comparisons are over , The same item was not found , Then print the result """
flag = 1
list01 = [3, 45, 5, 5, 80, 80, 1]
for r in range(len(list01) - 1):
for c in range(r + 1, len(list01)):
if list01[r] == list01[c]:
flag = 0
print("%d repeated " % list01[r])
break
if flag == 0:
break
else:
print(" No repeat ")
Matrix transformation turns columns into rows
list01 = [[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 11, 12],
[13, 14, 15, 16]]
list02 = []
for c in range(len(list01[0])):
list02.append([])
for r in range(len(list01)):
list02[c].append(list01[r][c])
print(
list02
)
""" List derivation nesting """
list01=["a","b","c"]
list02=["A","B","C"]
list04 =[ i+j for i in list01 for j in list02]
print(list04)
边栏推荐
猜你喜欢

一款好看的iapp捐赠榜单源码

看机器人教育引领素质教育主流
![[error reporting] node:internal/modules/cjs/loader:936 [solution]](/img/73/849c58c814c1a47dff0cde0e365c75.png)
[error reporting] node:internal/modules/cjs/loader:936 [solution]

第六天笔记

C language: Little Lele and Euclid

QT screen adaptive automatic layout, drag the window to automatically grow larger and smaller (I)

Small program source code for campus stray cat information recording and sharing / wechat cloud development medium big cat spectrum small program source code

PHP process communication series (I) named pipes

Shell script quick start-01

Some new ideas about time complexity
随机推荐
创客教育的起源和内涵的基本理念
(作业)C语言:atoi和strncpy、strncat、strncmp的模拟实现
Implement encapsulated public method global call in laravel framework
解析Steam教育中的项目式学习创造力
第五天实验
NVIDIA-VPI(Vision Programming Interface)
平凡的快乐
owt-server源码剖析(四)--video模块分析之Mixer Out
idea替换所有文件中的内容
多重继承与派生类成员标识
全新UI四方聚合支付系统源码/新增USDT提现/最新更新安全升级修复XSS漏洞补单漏洞
数仓中概念术语解析
Mqtt routine
看机器人教育引领素质教育主流
C语言:判断字母
New UI Sifang aggregate payment system source code / new usdt withdrawal / latest update security upgrade to fix XSS vulnerability patch vulnerability
架构师进阶,微服务设计与治理的 16 条常用原则
Really time NTP service startup command
STM32F103 learn the steps and template fool tutorial of 1-keil5 project establishment
网络基础概论