当前位置:网站首页>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)
边栏推荐
- Continuous learning / life long learning
- New UI Sifang aggregate payment system source code / new usdt withdrawal / latest update security upgrade to fix XSS vulnerability patch vulnerability
- owt-server源码剖析(四)--video模块分析之Mixer Out
- Zone --- line segment tree lazy marking board sub problem
- Thirty years of MPEG audio coding
- 白马过隙的时光
- C language: hollow square pattern
- C语言:空心正方形图案
- FFmpeg+SDL+QT实现简单是视频播放器
- nacos名字的由来
猜你喜欢

Etcd implementation of large-scale service governance application practice

第七天笔记

Rocbos open source micro community light forum source code

Source code and display of 18 classic programs in C language vs2019

Flink内核源码(七)Flink SQL提交流程

C language: Little Lele and Euclid

图书管理系统

Flink kernel source code (VII) Flink SQL submission process

Ffmpeg+sdl+qt is a simple video player

idea配置web容器与war打包
随机推荐
IOT components
QT compilation of IOT management platform 48 characteristic function design
CUDA details GPU architecture
优炫软件任命黄志军为公司总经理
Qt编写物联网管理平台48-特色功能设计
Implement encapsulated public method global call in laravel framework
Deliver temperature with science and technology, vivo appears at the digital China Construction Summit
第十天笔记
Mysql复合查询(重要)
Cloud development workers must go to work fishing and paddling wechat applet source code
Mqtt routine
STP协议(生成树协议)
并发模式之单例和不变模式
[error reporting] node:internal/modules/cjs/loader:936 [solution]
Intel's IPP Library (Integrated Performance Primitives)
Continuous learning / life long learning
Comic algorithm_ Xiaohuihui interview
time_ Wait and close_ Cause of wait
并发模式之异步回调Future模式
Stm32c8t6 encoder motor speed measurement and Arduino photoelectric module speed measurement