python这个列表[[1,2,3],[a,b,c],[r1,t1,y1] ]能用shuffle打乱吗?
时间: 2023-08-18 14:40:55 浏览: 32
是的,可以使用Python的random模块中的shuffle函数来打乱这个列表。示例代码如下:
```python
import random
my_list = [[1,2,3],['a','b','c'],['r1','t1','y1']]
random.shuffle(my_list)
print(my_list)
```
输出结果会是一个随机打乱的列表,类似于这样:
```
[['r1', 't1', 'y1'], ['a', 'b', 'c'], [1, 2, 3]]
```
注意,该函数会直接修改原始列表,而不是创建一个新的打乱后的列表。如果需要保留原始列表,可以先将其复制一份再进行打乱。
相关问题
python生成a-z拼接1-9自增数
以下是一个示例代码,可以生成a-z拼接1-9自增数:
```python
for i in range(1, 10):
for j in range(ord('a'), ord('z')+1):
print(chr(j) + str(i))
```
输出结果:
```
a1
b1
c1
d1
e1
f1
g1
h1
i1
j1
k1
l1
m1
n1
o1
p1
q1
r1
s1
t1
u1
v1
w1
x1
y1
z1
a2
b2
c2
d2
e2
f2
g2
h2
i2
j2
k2
l2
m2
n2
o2
p2
q2
r2
s2
t2
u2
v2
w2
x2
y2
z2
a3
b3
c3
d3
e3
f3
g3
h3
i3
j3
k3
l3
m3
n3
o3
p3
q3
r3
s3
t3
u3
v3
w3
x3
y3
z3
a4
b4
c4
d4
e4
f4
g4
h4
i4
j4
k4
l4
m4
n4
o4
p4
q4
r4
s4
t4
u4
v4
w4
x4
y4
z4
a5
b5
c5
d5
e5
f5
g5
h5
i5
j5
k5
l5
m5
n5
o5
p5
q5
r5
s5
t5
u5
v5
w5
x5
y5
z5
a6
b6
c6
d6
e6
f6
g6
h6
i6
j6
k6
l6
m6
n6
o6
p6
q6
r6
s6
t6
u6
v6
w6
x6
y6
z6
a7
b7
c7
d7
e7
f7
g7
h7
i7
j7
k7
l7
m7
n7
o7
p7
q7
r7
s7
t7
u7
v7
w7
x7
y7
z7
a8
b8
c8
d8
e8
f8
g8
h8
i8
j8
k8
l8
m8
n8
o8
p8
q8
r8
s8
t8
u8
v8
w8
x8
y8
z8
a9
b9
c9
d9
e9
f9
g9
h9
i9
j9
k9
l9
m9
n9
o9
p9
q9
r9
s9
t9
u9
v9
w9
x9
y9
z9
```
用python循环实现‘A1’到‘Z1’
可以使用 Python 的 `for` 循环和内置的 `chr()` 函数来实现:
```python
for c in range(ord('A'), ord('Z')+1):
print(chr(c) + '1')
```
这个代码会输出:
```
A1
B1
C1
D1
E1
F1
G1
H1
I1
J1
K1
L1
M1
N1
O1
P1
Q1
R1
S1
T1
U1
V1
W1
X1
Y1
Z1
```
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)