Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 months ago.
Improve this question
I have a list of words like below
["HEllO","HI","GREAT"]
and another list of tuples
[("HELLO",123),("HI",2134),("HELLO",65)]
If all the words in first list comes in second list atleast once then I need True as outcome else False.
Python version (based on comments from
Pranav Hosangadi and matszwecja)
a = ["HEllO","HI","GREAT"]
b = [("HELLO",123),("HI",2134),("HELLO",65)]
not (set(a) - set(x[0] for x in b))
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 months ago.
Improve this question
I am trying to fill out the statement of
initalise 2 empty list
in def monster_fight(monster1, monster2).
So far I have this.
def monster_fight(monster1, monster2):
# initalise 2 empty list for each monsters attacks that have been used to fight
What about:
empty_list = []
empty_list2 = list()
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed last year.
The community is reviewing whether to reopen this question as of 12 months ago.
Improve this question
I have this:
a = ['a','b','c','d','e','f']
And I want to make it into this:
a = ['ab','cd','ef']
I tried this:
for i in range(len(a)):
if round(i/2) > len(a):
break
c = (a[(i*2)-1])+(a[i*2])
c_list.append(c)
But it didn't work, and I felt it wasn't the best way to approach it.
def pair_up(a):
return [a[i]+a[i+1] for i in range(0,len(a),2)]
print(pair_up(a))
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I have a strings like '1,2,3' and '3,1,2'in a list, is there any way to compare these two strings and check that they are the same?
I have a lis a = ['G1G2G3,G4,G10','G4,G1G2G3,G10], i need a[0] == a[1] to return TRUE
Convert each string to a set, and compare the results.
>>> set('1,2,3'.split(',')) == set('3,1,2'.split(','))
True
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I tried to append these values in the list but it appends only else part.
I want to store these values i printed in a list. How can i achieve this??
for i in d["Cabin new"]:
if i=="nan":
print ("na")
else:
print (i[1:])
Append in both places:
res = []
for i in d["Cabin new"]:
if i=="nan":
res.append('na')
else:
res.append(i[1:])
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
these items are in a list
SF-04-08-010-MD01,
AHU-VVIP-02-003-MD03,
AHU-02-17-019-DPS03,
AHU-T3-01-PL-TS01,
EF-03-32-108-MD01,
AHU-02-16-019-MD01,
AHU-T3-01-003-MD01,
SF-04-08-010-MD01,
AHU-VVIP-02-003-MD03,
so i want a new list which should be like
SF-04-08
AHU-VVIP
AHU-02-17
AHU-T3-01
EF-03-32
AHU-02-16
AHU-T3-01
SF-04-08
AHU-VVIP-02
using python??
you can use strip like:
data = ['SF-04-08-010-MD01',
'AHU-VVIP-02-003-MD03',
'AHU-02-17-019-DPS03'
]
for item in data:
print ('-'.join(item.split('-')[:3]))
output:
SF-04-08
AHU-VVIP-02
AHU-02-17