当前位置:网站首页>双for循环
双for循环
2022-07-29 02:15:00 【qq_42307546】
for r in range(4):
for c in range(6):
if c % 2 == 0:
print("*", end="")
else:
print("#", end="")
print()
外循环控制行内控制列
“”"
0
01
012
0123
“”"
行固定为4行列要随着行变化
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()
列表排序(升序小–>大)
""" 两两比较 思想 取出第一个跟第二个比较 取出第二个跟三个比较 如果取出的元素大于第二个则交换位置 。。。。 """
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)
""" 判断列表元素具有相同的[3,80,45,5,80,1] 思路:所有元素两两比较,发现相同的则打印结果 所有元素比较结束,都没有发现相同项,则打印结果 """
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重复了" % list01[r])
break
if flag == 0:
break
else:
print("没有重复的")
矩阵转换将列变成行
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
)
""" 列表推导式嵌套 """
list01=["a","b","c"]
list02=["A","B","C"]
list04 =[ i+j for i in list01 for j in list02]
print(list04)
边栏推荐
- Read the recent trends of okaleido tiger and tap the value and potential behind it
- Tesla neural network model hydranet
- where、having、group by、order by,is null,not in,子查询,delete,日期函数
- After 4 years of testing experience, I finally entered Alibaba. Two months later, I chose to resign naked
- 主从复制及其原理
- 全新UI四方聚合支付系统源码/新增USDT提现/最新更新安全升级修复XSS漏洞补单漏洞
- Memories of many years ago
- 工程经济学简答题
- C language to achieve the three chess game
- What happens if you have to use ArrayList in multithreading?
猜你喜欢
VR safety training of mine mining virtual reality improves employees' vigilance and protection awareness
云开发打工人必备上班摸鱼划水微信小程序源码
C语言实现三子棋游戏
XSS靶场(二)xss.haozi
K210——声源定位、声音识别
Where, having, group by, order by, is null, not in, subquery, delete, date function
Meeting notice of meeting OA
PHP幸运抽奖系统带后台源码
ES6详解 快速上手!
Explain asynchronous tasks in detail: task status and lifecycle management
随机推荐
I want to talk about high concurrency.
Redis主从模式、哨兵集群、分片集群
ECCV 2022 | AirDet:无需微调的小样本目标检测方法
When synchronized encounters this thing, there is a big hole, so be careful
Mqtt routine
Understand the evolution of redis architecture in one article
After 4 years of testing experience, I finally entered Alibaba. Two months later, I chose to resign naked
where、having、group by、order by,is null,not in,子查询,delete,日期函数
JMeter's BeanShell generates MD5 encrypted data and writes it to the database
Ffmpeg+sdl+qt is a simple video player
h. 264 code stream explanation
ES6 detailed quick start!
6-21漏洞利用-mysql弱口令破解
The outsourcing company "mixed" for two years, and I only did five things seriously. Now I get byte offer smoothly.
C language to achieve the three chess game
Source code and display of 18 classic programs in C language vs2019
Altium designer outputs Gerber and other production documents
QT qstringlist usage
Summary of knowledge points of Engineering Economics
Kbxxxxx is not necessarily a patch, but also a description of a solution to a problem