My code:
def function():
resources, bufferViews, accessors = parse_gltf(fname)
display(resources)
display(bufferViews)
display(accessors)
ds = []
idx_vertex = -1
idx_normals = -1
idx_textures = -1
idx_meshes = -1
for j in range(len(accessors)):
accessor = accessors[j]
if accessor.min:
idx_vertex = j
d = parse_accessor(accessor, resources, bufferViews)
ds.append(d)
if d.shape[1] == 3:
idx_normals = j
if d.shape[1] == 2:
idx_textures = j
if d.shape[1] == 1:
idx_meshes = j
return idx_vertex, idx_normals, idx_textures, idx_meshes, [e.shape for e in ds]
if __name__ == "main":
idx_vertex, idx_normals, idx_textures, idx_meshes, [e.shape for e in ds] = function()
display(ds[idx_vertex])
Basically, I want to be able to return the values idx_vertex, idx_normals, idx_textures, idx_meshes and be able to assign them in the ds array. However, I get "SyntaxError: cannot assign to list comprehension" when I try to achieve this. Does anyone know what I am doing wrong?
You need to store the list comprehension in a variable in your start routine:
if __name__ == "__main__":
idx_vertex, idx_normals, idx_textures, idx_meshes, shape_list = function()
display(ds[idx_vertex])
Your function function is already returning the list [e.shape for e in ds]
LE: Edited according to MattDMO's comment
Related
The Code does not go in the If Statement no matter what (where I intend to alter the array "dop", I have no idea why. Any Help will be appreciated
#The Array dop
dop = ["1878[1879]","1877","[2016]2015","1874","[2871]2987","3012[2019]"]
i = 0;
#Used Try Catch Block because of the Type Error that occurs when '[' is not found in an array
#Element
while(i < 6):
try:
strObject = dop[i]
print(strObject)
indexOne = strObject.index('[',0)
indexTwo = strObject.index(']',0)
print(indexOne)
print(indexTwo)
if (indexOne != 0 | indexOne != -1):
substringObject = strObject[0:indexOne]
dop[i] = substringObject
i = i+1
print(i)
elif (indexOne == -1):
i = i+1
elif (indexOne == 0):
substringObject = strObject[indexTwo]
dop[i] = substringObject
i = i+1
except ValueError:
print("Goes Here")
i = i+1
print(i)
i = i+1
So in VSCode, I'm receiving this error...
Given the input
2
21 22
We have variables saying
best_choice = '22'
a: ['21', '22']
However, a.remove(best_choice) returns an error.
I am completely confounded... please help.
I checked for this problem on stacks and found that remove() doesn't work when iterating through a list, so I changed my loop to while(True). However, I'm still receiving the same error.
Here is the code:
import sys
def best_option(a):
iterator = 0
while(len(a)>1):
previous_best_digit = 0
current_best_digit = 0
best_short_option = []
return_list = []
for item in a:
if len(item)-1 < iterator:
char_previous = item[iterator-1:iterator]
dig_previous = ord(char_previous)
previous_best_digit = dig_previous
best_short_option = item
continue
char = item[iterator:iterator+1]
dig = ord(char)
if dig > current_best_digit:
current_best_digit = dig
return_list.clear()
return_list.append(item)
elif dig == current_best_digit:
return_list.append(item)
if (current_best_digit < previous_best_digit):
return_list.clear()
return_list.append(best_short_option)
a = return_list
iterator+=1
return a
def largest_number(a):
#write your code here
res = ""
while (True):
best_choice = best_option(a)
print(best_choice)
a.remove(best_choice)
res += best_choice
if (len(a)==1):
break
res.append(a)
print(res)
return res
if __name__ == '__main__':
input = sys.stdin.read()
data = input.split()
a = data[1:]
print(largest_number(a))
It's purpose create a string with the greatest possible value from a list of strings.
your best_choice is ['22'], not '22'
Write a python function, check_anagram() which accepts two strings and returns True, if one string is an anagram of another string. Otherwise returns False.
The two strings are considered to be an anagram if they contain repeating characters but none of the characters repeat at the same position. The length of the strings should be the same.
Note: Perform case insensitive comparison wherever applicable.
This is my code:
def check_anagram(data1,data2):
first = data1.lower()
second = data2.lower()
d1 = []
d2 = []
for i in range(0, len(first)):
d1.append(first[i])
for i in range(0, len(second)):
d2.append(second[i])
for_check1 = sorted(d1)
for_check2 = sorted(d2)
if (for_check1 != for_check2):
return False
count = 0
if (len(d1) == len(d2)):
for i in d1:
for j in d2:
if(i == j):
a = d1.index(i)
b = d2.index(j)
if(a == b):
return False
else:
count += 1
if(count == len(first)):
return True
else:
return False
print(check_anagram("Schoolmaster", "Theclassroom"))
The output I am getting is "False"
Although this program is giving relevant output for string values like {silent, listen}{Moonstarrer, Astronomer}{apple, mango} but not for the above two strings(in code)
What cases am I missing in this code?? How to rectify this thing?
Your function could be simplified as:
def check_anagram(data1, data2):
data1 = data1.lower()
data2 = data2.lower()
if sorted(data1) != sorted(data2):
return False
return all(data1[i] != data2[i] for i in range(len(data1)))
Which actually works for the case you specified.
your code is correct just write len(second) instead of count.
def check_anagram(data1,data2):
first = data1.lower()
second = data2.lower()
d1 = []
d2 = []
for i in range(0, len(first)):
d1.append(first[i])
for i in range(0, len(second)):
d2.append(second[i])
for_check1 = sorted(d1)
for_check2 = sorted(d2)
if (for_check1 != for_check2):
return False
count = 0
if (len(d1) == len(d2)):
for i in d1:
for j in d2:
if(i == j):
a = d1.index(i)
b = d2.index(j)
if(a == b):
return False
else:
count += 1
if(len(second) == len(first)):
return True
else:
return False
print(check_anagram("Schoolmaster", "Theclassroom"))
This program of mine is clearing all possible test cases.
def check_anagram(data1,data2):
data1=data1.lower()
data2=data2.lower()
if(len(data1)==len(data2)):
if(sorted(data1)!=sorted(data2)):
return False
else:
if(data1[i]!=data2[i] for i in range(len(data1))):
return True
else:
return False
else:
return False
print(check_anagram("eat","tea"))
Below is the hacker rank code and x is not being mapped to instance args.Can someone please provide me with a reason?https://www.hackerrank.com/challenges/python-lists/problem
if __name__ == '__main__':
N = int(input())
l=[]
for _ in range(N):
line = input().split()
cmd = line[0]
args= line[1:] # <=> here we have 0, 1 or 2 parameters, right?
"""if cmd!= "print":
cmd += "(" + ",".join(args)+")"""
#x = ",".join(map(str,args))
if len(args) == 2:
x, y = map(int, args)
if cmd == "insert":
l.insert(x, y)
elif len(args) == 1:
x = map(int,args)
if cmd == "remove":
l.remove(x)
elif cmd == "append":
l.append(x)
elif cmd == "sort":
l.sorted()
elif cmd == "pop":
l.pop()
elif cmd =="reverse":
l.reverse()
elif cmd == 'print':
print(l)
Your issue is with this line:
x = map(int,args)
This does not work like the line you have in a different branch of your code:
x, y = map(int, args)
The reason is that the first one binds the name x to the map call. It doesn't unpack the map object to get the single value it will yield. For that you'd need:
x, = map(int, args) # note the comma!
But if you know that you have only a single value in args, there's really no need to call map on it at all. Just use x = int(args[0]) instead.
You have couple of issues in your code.
By x = map(int,args) (line 16), x becomes a map object. To obtain integer from this map, first convert it into a list and then use indexing. x = list(map(int,args))[0] will solve your issue. Or you could simply use x = int(args[0]).
list has no sorted function, change l.sorted() to l.sort().
as the title say i have been searching the solution of this problem :
TypeError: 'list' object is not callable
for a while, but i did find only answers about naming variables with defaults names like, for instance, list. And i think this is not my case, in particular this the concerned code:
next_matrix = 0
c = 0
routes = []
mapp_matrix = []
mapp = []
def del_nl(l):
for i in range(len(l)):
del l[i][-1]
# check if there is a valid route in a map from a starting point
def route(n_map, n_command, s_point):
for i in n_command:
if i == 'N':
s_point[0] = s_point[0] - 1
elif i == 'S':
s_point[0] = s_point[0] + 1
elif i == 'E':
s_point[1] = s_point[1] + 1
elif i == 'W':
s_point[1] = s_point[1] -1
try:
if n_map[s_point[0]][s_point[1]] != '.':
return False
except IndexError:
return False
return True
## Getting datas for every map ##
with open("/home/senso/programming/ctf_magio/input-sample.txt", "r") as f:
for line in f:
# i am reading values for the dimension of the map
if c == next_matrix:
line = line.split(" ")
int_list = [int(i) for i in line]
if not c == 0:
del_nl(mapp)
mapp_matrix.append(mapp[:])
del mapp[:]
# reading the commands
elif c == next_matrix + 1:
route = list(line)
del route[-1]
routes.append(route)
next_matrix = next_matrix + int_list[0] + 2
else:
#building the map
mapp.append(list(line))
c = c+1
del_nl(mapp)
mapp_matrix.append(mapp[:])
ship_alive = 0
for i in range(len(mapp_matrix)):
for j in range(len(mapp_matrix[i])):
for z in range(len(mapp_matrix[i][j])):
#oh my god is O(n^3), will it explode??
if mapp_matrix[i][j][z] == '.':
point = [j, z]
if route(mapp_matrix[i], routes[i], point):
ship_alive = 1 + ship_alive
and i get this error
File "capitanSonar.py", line 78, in
if route(mapp_matrix[i], routes[i], point):
TypeError: 'list' object is not callable
If i try to call 'route' with static lists it works.
Any help is appreciated.
# reading the commands
elif c == next_matrix + 1:
route = list(line) # <- Here. Pick a different name for the list
del route[-1]
routes.append(route)
next_matrix = next_matrix + int_list[0] + 2
else:
#building the map
mapp.append(list(line))
c = c+1