Điều này có lẽ khá đơn giản, nhưng tôi có một danh sách với các chuỗi cũng tương ứng với các tên biến:
listname = ['name1', 'name2," ... ]
name1 = "somestring"
name2 = "some other string"
Những gì tôi muốn có thể làm là một cái gì đó như:
for variable in listname:
[perform some operation on the string associated with the variables
named in listname, i.e. "somestring" and then "some other string," etc.]
Có một cách dễ dàng để buộc đánh giá các chuỗi trong listname
là biến?
Đã hỏi ngày 15 tháng 7 năm 2013 lúc 5:07Jul 15, 2013 at 5:07
Bạn không muốn làm điều này. Sử dụng từ điển:
d = {'name1':name1, 'name2':name2}
for myvar in listname:
myvar = d.get[myvar]
do_stuff[myvar]
Đã trả lời ngày 15 tháng 7 năm 2013 lúc 5:10Jul 15, 2013 at 5:10
TerryaterryaTerryA
57.3K11 Huy hiệu vàng117 Huy hiệu bạc139 Huy hiệu đồng11 gold badges117 silver badges139 bronze badges
0
Có những lúc điều này có thể hữu ích
for variable in listname:
target = vars[].get[variable]
Thông thường, tốt hơn là chỉ cần có một danh sách các đối tượng hoặc sử dụng một không gian tên riêng như @haidro gợi ý
Đã trả lời ngày 15 tháng 7 năm 2013 lúc 5:10Jul 15, 2013 at 5:10
TerryaterryaJohn La Rooy
57.3K11 Huy hiệu vàng117 Huy hiệu bạc139 Huy hiệu đồng51 gold badges359 silver badges500 bronze badges
1
For item in string_list:
# possibly do some string manipulation such as
# item = item + '+= 1'
eval[item]
# or even exec[item]
Đã trả lời ngày 15 tháng 7 năm 2013 lúc 5:10Jul 15, 2013 at 5:10
TerryaterryaSteve Barnes
57.3K11 Huy hiệu vàng117 Huy hiệu bạc139 Huy hiệu đồng6 gold badges60 silver badges70 bronze badges
4
Có những lúc điều này có thể hữu ích
name1 = "some string"
name2 = "some other string"
listname =[name1, name2]
for s in listname:
do something with s
Thông thường, tốt hơn là chỉ cần có một danh sách các đối tượng hoặc sử dụng một không gian tên riêng như @haidro gợi ýJul 15, 2013 at 5:27
John La Rooyjohn La RooyKeith
Phù bằng vàng 287K5110 gold badges56 silver badges75 bronze badges
Xem thảo luận
Cải thiện bài viết
Lưu bài viết
Xem thảo luận
Cải thiện bài viết
Lưu bài viết
Đọc
Examples:
Input : list = [10, 20, 30, 40, 50] given value = 20 Output : No Input : list = [10, 20, 30, 40, 50] given value = 5 Output : Yes
Bàn luận{IDE} first, before moving on to the solution.
Cho một danh sách, in tất cả các giá trị trong một danh sách lớn hơn giá trị đã cho & nbsp;
Được đề xuất: Vui lòng thử cách tiếp cận của bạn trên {IDE} trước, trước khi chuyển sang giải pháp.
Implementation:
Python
def
check[list1, val]:
Phương pháp 1: Danh sách truyền tải
Bằng cách đi qua trong danh sách, chúng ta có thể so sánh mọi yếu tố và kiểm tra xem tất cả các phần tử trong danh sách đã cho có lớn hơn giá trị đã cho hay không. & NBSP;
for variable in listname:
[perform some operation on the string associated with the variables
named in listname, i.e. "somestring" and then "some other string," etc.]
0____11 for variable in listname:
[perform some operation on the string associated with the variables
named in listname, i.e. "somestring" and then "some other string," etc.]
2for variable in listname:
[perform some operation on the string associated with the variables
named in listname, i.e. "somestring" and then "some other string," etc.]
3 for variable in listname:
[perform some operation on the string associated with the variables
named in listname, i.e. "somestring" and then "some other string," etc.]
4for variable in listname:
[perform some operation on the string associated with the variables
named in listname, i.e. "somestring" and then "some other string," etc.]
5for variable in listname:
[perform some operation on the string associated with the variables
named in listname, i.e. "somestring" and then "some other string," etc.]
6 for variable in listname:
[perform some operation on the string associated with the variables
named in listname, i.e. "somestring" and then "some other string," etc.]
7for variable in listname:
[perform some operation on the string associated with the variables
named in listname, i.e. "somestring" and then "some other string," etc.]
8 for variable in listname:
[perform some operation on the string associated with the variables
named in listname, i.e. "somestring" and then "some other string," etc.]
9d = {'name1':name1, 'name2':name2}
for myvar in listname:
myvar = d.get[myvar]
do_stuff[myvar]
6for variable in listname:
[perform some operation on the string associated with the variables
named in listname, i.e. "somestring" and then "some other string," etc.]
8d = {'name1':name1, 'name2':name2}
for myvar in listname:
myvar = d.get[myvar]
do_stuff[myvar]
8d = {'name1':name1, 'name2':name2}
for myvar in listname:
myvar = d.get[myvar]
do_stuff[myvar]
9for variable in listname:
target = vars[].get[variable]
0for variable in listname:
target = vars[].get[variable]
1for variable in listname:
target = vars[].get[variable]
0for variable in listname:
target = vars[].get[variable]
3for variable in listname:
target = vars[].get[variable]
0for variable in listname:
target = vars[].get[variable]
5for variable in listname:
target = vars[].get[variable]
0for variable in listname:
target = vars[].get[variable]
7for variable in listname:
target = vars[].get[variable]
0for variable in listname:
target = vars[].get[variable]
9For item in string_list:
# possibly do some string manipulation such as
# item = item + '+= 1'
eval[item]
# or even exec[item]
0
For item in string_list:
# possibly do some string manipulation such as
# item = item + '+= 1'
eval[item]
# or even exec[item]
1for variable in listname:
[perform some operation on the string associated with the variables
named in listname, i.e. "somestring" and then "some other string," etc.]
8 For item in string_list:
# possibly do some string manipulation such as
# item = item + '+= 1'
eval[item]
# or even exec[item]
3for variable in listname:
[perform some operation on the string associated with the variables
named in listname, i.e. "somestring" and then "some other string," etc.]
6For item in string_list:
# possibly do some string manipulation such as
# item = item + '+= 1'
eval[item]
# or even exec[item]
5for variable in listname:
[perform some operation on the string associated with the variables
named in listname, i.e. "somestring" and then "some other string," etc.]
0For item in string_list:
# possibly do some string manipulation such as
# item = item + '+= 1'
eval[item]
# or even exec[item]
7For item in string_list:
# possibly do some string manipulation such as
# item = item + '+= 1'
eval[item]
# or even exec[item]
8For item in string_list:
# possibly do some string manipulation such as
# item = item + '+= 1'
eval[item]
# or even exec[item]
9name1 = "some string"
name2 = "some other string"
listname =[name1, name2]
for s in listname:
do something with s
0for variable in listname:
[perform some operation on the string associated with the variables
named in listname, i.e. "somestring" and then "some other string," etc.]
0For item in string_list:
# possibly do some string manipulation such as
# item = item + '+= 1'
eval[item]
# or even exec[item]
7name1 = "some string"
name2 = "some other string"
listname =[name1, name2]
for s in listname:
do something with s
3For item in string_list:
# possibly do some string manipulation such as
# item = item + '+= 1'
eval[item]
# or even exec[item]
1for variable in listname:
[perform some operation on the string associated with the variables
named in listname, i.e. "somestring" and then "some other string," etc.]
8 for variable in listname:
target = vars[].get[variable]
1for variable in listname:
[perform some operation on the string associated with the variables
named in listname, i.e. "somestring" and then "some other string," etc.]
6For item in string_list:
# possibly do some string manipulation such as
# item = item + '+= 1'
eval[item]
# or even exec[item]
5for variable in listname:
[perform some operation on the string associated with the variables
named in listname, i.e. "somestring" and then "some other string," etc.]
0For item in string_list:
# possibly do some string manipulation such as
# item = item + '+= 1'
eval[item]
# or even exec[item]
7For item in string_list:
# possibly do some string manipulation such as
# item = item + '+= 1'
eval[item]
# or even exec[item]
8For item in string_list:
# possibly do some string manipulation such as
# item = item + '+= 1'
eval[item]
# or even exec[item]
9name1 = "some string"
name2 = "some other string"
listname =[name1, name2]
for s in listname:
do something with s
0for variable in listname:
[perform some operation on the string associated with the variables
named in listname, i.e. "somestring" and then "some other string," etc.]
0For item in string_list:
# possibly do some string manipulation such as
# item = item + '+= 1'
eval[item]
# or even exec[item]
7name1 = "some string"
name2 = "some other string"
listname =[name1, name2]
for s in listname:
do something with s
3
6 for variable in listname:
[perform some operation on the string associated with the variables
named in listname, i.e. "somestring" and then "some other string," etc.]
5For item in string_list:
# possibly do some string manipulation such as
# item = item + '+= 1'
eval[item]
# or even exec[item]
Phương pháp 3: Sử dụng phương thức Min []
Implementation:
Python
def
check[list1, val]:
Các
d = {'name1':name1, 'name2':name2}
for myvar in listname:
myvar = d.get[myvar]
do_stuff[myvar]
6for variable in listname:
[perform some operation on the string associated with the variables
named in listname, i.e. "somestring" and then "some other string," etc.]
8d = {'name1':name1, 'name2':name2}
for myvar in listname:
myvar = d.get[myvar]
do_stuff[myvar]
8d = {'name1':name1, 'name2':name2}
for myvar in listname:
myvar = d.get[myvar]
do_stuff[myvar]
9for variable in listname:
target = vars[].get[variable]
0for variable in listname:
target = vars[].get[variable]
1for variable in listname:
target = vars[].get[variable]
0for variable in listname:
target = vars[].get[variable]
3for variable in listname:
target = vars[].get[variable]
0for variable in listname:
target = vars[].get[variable]
5for variable in listname:
target = vars[].get[variable]
0for variable in listname:
target = vars[].get[variable]
7for variable in listname:
target = vars[].get[variable]
0for variable in listname:
target = vars[].get[variable]
9For item in string_list:
# possibly do some string manipulation such as
# item = item + '+= 1'
eval[item]
# or even exec[item]
0For item in string_list:
# possibly do some string manipulation such as
# item = item + '+= 1'
eval[item]
# or even exec[item]
1for variable in listname:
[perform some operation on the string associated with the variables
named in listname, i.e. "somestring" and then "some other string," etc.]
8 For item in string_list:
# possibly do some string manipulation such as
# item = item + '+= 1'
eval[item]
# or even exec[item]
3for variable in listname:
[perform some operation on the string associated with the variables
named in listname, i.e. "somestring" and then "some other string," etc.]
6For item in string_list:
# possibly do some string manipulation such as
# item = item + '+= 1'
eval[item]
# or even exec[item]
5for variable in listname:
[perform some operation on the string associated with the variables
named in listname, i.e. "somestring" and then "some other string," etc.]
0For item in string_list:
# possibly do some string manipulation such as
# item = item + '+= 1'
eval[item]
# or even exec[item]
7For item in string_list:
# possibly do some string manipulation such as
# item = item + '+= 1'
eval[item]
# or even exec[item]
8For item in string_list:
# possibly do some string manipulation such as
# item = item + '+= 1'
eval[item]
# or even exec[item]
9name1 = "some string"
name2 = "some other string"
listname =[name1, name2]
for s in listname:
do something with s
0for variable in listname:
[perform some operation on the string associated with the variables
named in listname, i.e. "somestring" and then "some other string," etc.]
0For item in string_list:
# possibly do some string manipulation such as
# item = item + '+= 1'
eval[item]
# or even exec[item]
7name1 = "some string"
name2 = "some other string"
listname =[name1, name2]
for s in listname:
do something with s
3For item in string_list:
# possibly do some string manipulation such as
# item = item + '+= 1'
eval[item]
# or even exec[item]
1for variable in listname:
[perform some operation on the string associated with the variables
named in listname, i.e. "somestring" and then "some other string," etc.]
8 for variable in listname:
target = vars[].get[variable]
1for variable in listname:
[perform some operation on the string associated with the variables
named in listname, i.e. "somestring" and then "some other string," etc.]
6 For item in string_list:
# possibly do some string manipulation such as
# item = item + '+= 1'
eval[item]
# or even exec[item]
5for variable in listname:
[perform some operation on the string associated with the variables
named in listname, i.e. "somestring" and then "some other string," etc.]
0For item in string_list:
# possibly do some string manipulation such as
# item = item + '+= 1'
eval[item]
# or even exec[item]
7For item in string_list:
# possibly do some string manipulation such as
# item = item + '+= 1'
eval[item]
# or even exec[item]
8For item in string_list:
# possibly do some string manipulation such as
# item = item + '+= 1'
eval[item]
# or even exec[item]
9name1 = "some string"
name2 = "some other string"
listname =[name1, name2]
for s in listname:
do something with s
0for variable in listname:
[perform some operation on the string associated with the variables
named in listname, i.e. "somestring" and then "some other string," etc.]
0For item in string_list:
# possibly do some string manipulation such as
# item = item + '+= 1'
eval[item]
# or even exec[item]
7name1 = "some string"
name2 = "some other string"
listname =[name1, name2]
for s in listname:
do something with s
3Phương pháp 3: Sử dụng phương thức Min []
Python3
d = {'name1':name1, 'name2':name2}
for myvar in listname:
myvar = d.get[myvar]
do_stuff[myvar]
6for variable in listname:
[perform some operation on the string associated with the variables
named in listname, i.e. "somestring" and then "some other string," etc.]
8d = {'name1':name1, 'name2':name2}
for myvar in listname:
myvar = d.get[myvar]
do_stuff[myvar]
8d = {'name1':name1, 'name2':name2}
for myvar in listname:
myvar = d.get[myvar]
do_stuff[myvar]
9for variable in listname:
target = vars[].get[variable]
0for variable in listname:
target = vars[].get[variable]
1for variable in listname:
target = vars[].get[variable]
0for variable in listname:
target = vars[].get[variable]
3for variable in listname:
target = vars[].get[variable]
0for variable in listname:
target = vars[].get[variable]
5for variable in listname:
target = vars[].get[variable]
0for variable in listname:
target = vars[].get[variable]
7for variable in listname:
target = vars[].get[variable]
0for variable in listname:
target = vars[].get[variable]
9For item in string_list:
# possibly do some string manipulation such as
# item = item + '+= 1'
eval[item]
# or even exec[item]
0For item in string_list:
# possibly do some string manipulation such as
# item = item + '+= 1'
eval[item]
# or even exec[item]
1for variable in listname:
[perform some operation on the string associated with the variables
named in listname, i.e. "somestring" and then "some other string," etc.]
8 For item in string_list:
# possibly do some string manipulation such as
# item = item + '+= 1'
eval[item]
# or even exec[item]
3for variable in listname:
[perform some operation on the string associated with the variables
named in listname, i.e. "somestring" and then "some other string," etc.]
6listname
1for variable in listname:
[perform some operation on the string associated with the variables
named in listname, i.e. "somestring" and then "some other string," etc.]
39for variable in listname:
[perform some operation on the string associated with the variables
named in listname, i.e. "somestring" and then "some other string," etc.]
40for variable in listname:
[perform some operation on the string associated with the variables
named in listname, i.e. "somestring" and then "some other string," etc.]
8for variable in listname:
[perform some operation on the string associated with the variables
named in listname, i.e. "somestring" and then "some other string," etc.]
42for variable in listname:
[perform some operation on the string associated with the variables
named in listname, i.e. "somestring" and then "some other string," etc.]
0For item in string_list:
# possibly do some string manipulation such as
# item = item + '+= 1'
eval[item]
# or even exec[item]
7listname
1For item in string_list:
# possibly do some string manipulation such as
# item = item + '+= 1'
eval[item]
# or even exec[item]
8for variable in listname:
[perform some operation on the string associated with the variables
named in listname, i.e. "somestring" and then "some other string," etc.]
47For item in string_list:
# possibly do some string manipulation such as
# item = item + '+= 1'
eval[item]
# or even exec[item]
9name1 = "some string"
name2 = "some other string"
listname =[name1, name2]
for s in listname:
do something with s
0for variable in listname:
[perform some operation on the string associated with the variables
named in listname, i.e. "somestring" and then "some other string," etc.]
0For item in string_list:
# possibly do some string manipulation such as
# item = item + '+= 1'
eval[item]
# or even exec[item]
7listname
1name1 = "some string"
name2 = "some other string"
listname =[name1, name2]
for s in listname:
do something with s
3for variable in listname:
[perform some operation on the string associated with the variables
named in listname, i.e. "somestring" and then "some other string," etc.]
47