![]() |
convert multi list to one list ! - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: convert multi list to one list ! (/thread-14171.html) |
convert multi list to one list ! - evilcode1 - Nov-18-2018 hello all ... this is my code : #qassam = raw_input() def loop(): for i in range(12): qan = "Key.f{}".format(i+1) print qan.split() ''' if qassam in qan: print "yes" else: print "no" ''' loop()output : i need to convert them to one list like [ 'Key.f1' , 'Key.f2' , 'Key.f3' ....ect ]
RE: convert multi list to one list ! - j.crater - Nov-18-2018 Hello, you can do something like this: def loop(): my_list = [] for i in range(12): qan = "Key.f{}".format(i+1) my_list.append(qan) print my_list RE: convert multi list to one list ! - snippsat - Nov-18-2018 It's also a hint on upgrading to make this work for you ![]() >>> [f"Key.f{i}" for i in range(1, 13)] ['Key.f1', 'Key.f2', 'Key.f3', 'Key.f4', 'Key.f5', 'Key.f6', 'Key.f7', 'Key.f8', 'Key.f9', 'Key.f10', 'Key.f11', 'Key.f12'] RE: convert multi list to one list ! - evilcode1 - Nov-18-2018 (Nov-18-2018, 08:46 AM)j.crater Wrote: Hello, you can do something like this: this works : def loop(): my_list = [] for i in range(12): qan = "Key.f{}".format(i+1) my_list.append(qan) print my_list thank u my friend <3(Nov-18-2018, 09:49 AM)snippsat Wrote: It's also a hint on upgrading to make this work for you thank u for ur help <3 |